Basic Calculated
Fields in Tableau
Learn to create custom calculations using math, string, date, and boolean logic to unlock deeper insights in your visualizations.
What Is a Calculated Field?
A calculated field is a new column you create in Tableau using a formula. It does not exist in the original data source: Tableau computes it on the fly from existing fields, constants, and functions.
Why Use Calculated Fields?
The Four Calculation Types
Every calculated field uses one or more of these categories. Many real-world formulas combine them.
Math Calculations
Use standard arithmetic operators to derive new numeric fields from existing ones.
[Profit] / [Sales]
// Revenue per Unit
[Sales] / [Quantity]
// Discount Amount
[Sales] * [Discount]
String Calculations
Manipulate text fields: extract parts, change case, search for patterns, or combine values.
UPPER([Category])
// First 3 characters of Product ID
LEFT([Product ID], 3)
// Combine first and last name
[First Name] + " " + [Last Name]
Date Calculations
Work with dates to compute durations, extract components, or shift time periods.
DATEDIFF('day', [Order Date], TODAY())
// Extract the year
YEAR([Order Date])
// Add 30 days to ship date
DATEADD('day', 30, [Ship Date])
Boolean Logic
Use conditional logic to classify, filter, or flag rows based on rules you define.
IF [Profit] \(> 0\) THEN "Profitable"
ELSE "Not Profitable"
END
// Multi-condition
IF [Sales] \(> 1000\) AND [Profit] \(> 200\)
THEN "High Value"
ELSE "Standard"
END
IF vs CASE: Key Distinction
| IF / ELSEIF / END | CASE / WHEN / END | |
|---|---|---|
| Tests | Any condition (ranges, \(\gt\), \(\lt\), AND/OR) | Exact match on a single field |
| Flexibility | High: different fields per branch | Lower: one field, many values |
| Readability | Good for 2-3 branches | Cleaner for many categories |
| Example Use | IF \([Profit] > 0\) ... | CASE [Region] WHEN ... |
How to Create a Calculated Field
Example 1: Profit Margin
Goal: Calculate profit as a percentage of sales for each row.
[Profit] / [Sales]
Example 2: Region Grouping with CASE
Goal: Map four regions to two broader zones: "East" and "West".
WHEN "East" THEN "Eastern Zone"
WHEN "South" THEN "Eastern Zone"
WHEN "West" THEN "Western Zone"
WHEN "Central" THEN "Western Zone"
END
Example 3: Combining Types
Goal: Flag orders that shipped more than 5 days after the order date and label them by priority.
THEN "Late: " + STR(
DATEDIFF('day', [Order Date], [Ship Date])
) + " days"
ELSE "On Time"
END
Common Mistakes
Summary Cheat Sheet
| Type | Key Functions | Example |
|---|---|---|
| Math | \(+\), \(-\), \(*\), \(/\), \(\%\), ABS, ROUND | \([Profit] / [Sales]\) |
| String | UPPER LEFT CONTAINS REPLACE TRIM | UPPER([Category]) |
| Date | DATEDIFF DATEADD YEAR MONTH TODAY | DATEDIFF('day', [Order], TODAY()) |
| Boolean | IF CASE IIF AND OR NOT | IF \([Profit] > 0\) THEN ... END |
Question 1 of 5
Which Tableau function would you use to find the number of days between two dates?
Question 2 of 5
What is the output of LEFT("Tableau", 3)?
Question 3 of 5
You write: IF \([Sales] > 1000\) THEN "High". Tableau shows a syntax error. What is missing?
Question 4 of 5
You need to calculate \([Sales] / [Quantity]\), but some rows have \([Quantity] = 0\). Which approach prevents errors?
Question 5 of 5
Which statement is best suited for mapping a single field to many specific values (e.g., mapping region codes to full names)?