Tableau Calculated Fields

Calculated fields let you create new data fields from existing ones using formulas. If your data has Sales and Cost columns but no Profit column, you create Profit yourself: Sales minus Cost. Calculated fields live in Tableau — your original data source stays unchanged.

Why Use Calculated Fields

Raw data rarely comes in the exact form you need for analysis. You might need to combine first name and last name into one field, calculate profit margins, classify customers into tiers, or convert units. Calculated fields handle all of these without touching your original data.

Creating a Calculated Field

  1. Go to Analysis menu → Create Calculated Field (or right-click in the Data Pane → Create → Calculated Field)
  2. A formula editor opens
  3. Type your formula using field names in square brackets: [Sales] - [Cost]
  4. Give the field a name (e.g., "Profit")
  5. Click OK
  6. The new field appears in the Data Pane ready to drag into any chart

Basic Arithmetic Calculations

The simplest calculated fields use basic math operators.

Examples

GoalFormula
Profit = Sales minus Cost[Sales] - [Cost]
Profit Margin percentage[Profit] / [Sales]
Revenue per Unit[Revenue] / [Units Sold]
Sales with Tax (10%)[Sales] * 1.10
Discounted Price[Price] * (1 - [Discount])

String Calculations

String functions work on text fields. Combine, split, or reformat text using these built-in functions.

Diagram: String Function Examples

Original Data:
  First Name: "John"
  Last Name:  "Smith"

Formula: [First Name] + " " + [Last Name]
Result:  "John Smith"

----------------------------------------------

Original: "  hello world  " (spaces on both sides)
Formula: TRIM("  hello world  ")
Result:  "hello world"

----------------------------------------------

Original: "john.smith@email.com"
Formula: UPPER([Email])
Result:  "JOHN.SMITH@EMAIL.COM"

IF/THEN Logic in Calculated Fields

Use IF statements to classify data into categories based on conditions.

Customer Tier Classification

Formula:
IF [Sales] >= 10000 THEN "Gold"
ELSEIF [Sales] >= 5000 THEN "Silver"
ELSE "Bronze"
END

Result field "Customer Tier":
  Customer A — Sales $12,000 → Gold
  Customer B — Sales $6,500  → Silver
  Customer C — Sales $2,000  → Bronze

CASE Statements

CASE statements compare one field to multiple values. They are cleaner than long IF-ELSEIF chains when you match specific values.

Example: Region Abbreviation

Formula:
CASE [Region]
  WHEN "East"    THEN "E"
  WHEN "West"    THEN "W"
  WHEN "South"   THEN "S"
  WHEN "Central" THEN "C"
  ELSE "Unknown"
END

Date Calculations

Date functions extract parts of a date or calculate differences between dates.

Common Date Formulas

GoalFormula
Year from Order DateYEAR([Order Date])
Month name from dateDATENAME('month', [Order Date])
Days between order and shipDATEDIFF('day', [Order Date], [Ship Date])
Add 30 days to a dateDATEADD('day', 30, [Order Date])
First day of the monthDATETRUNC('month', [Order Date])

Logical Functions: AND, OR, NOT

Combine multiple conditions in one formula.

Example: High-Value Low-Discount Orders

Formula:
IF [Sales] > 5000 AND [Discount] = 0
THEN "Premium Full-Price Order"
ELSE "Standard Order"
END

→ Flags orders where sales are high AND no discount was given

Handling Nulls in Calculations

Null values break many calculations. Use ISNULL() or ZN() to handle them safely.

ZN([Sales])       → Returns 0 if Sales is NULL, otherwise returns Sales
ISNULL([Region])  → Returns TRUE if Region is empty
IFNULL([Region], "Unknown")  → Replaces NULL with "Unknown"

The Formula Editor Features

The formula editor provides live feedback as you type. A green checkmark at the bottom means your formula is valid. A red indicator with a message means there is a syntax error — Tableau tells you exactly what went wrong. The right side of the editor shows a searchable list of all available functions with descriptions.

Diagram: Formula Editor

+-------------------------------------------+
|  Name: Profit Margin                      |
+-------------------------------------------+
|  [Profit] / [Sales]                       |
|                                           |
|  ✓ The calculation is valid.              |
+-------------------------------------------+
|  Function List:        | Description      |
|  ABS()                 | Absolute value   |
|  AVG()                 | Average          |
|  CEILING()             | Round up         |
|  DATE()                | Date conversion  |
+-------------------------------------------+

Summary

Calculated fields extend your data without changing the source. Use arithmetic for profit margins and ratios, string functions for text cleanup and combination, IF/CASE statements for classification logic, and date functions for time-based analysis. The formula editor validates your syntax in real time. Every calculated field appears in the Data Pane and works exactly like any original field — drag it to any shelf, filter it, or use it in other calculated fields.

Leave a Comment

Your email address will not be published. Required fields are marked *