Debugging
Calculations
Master the art of finding and fixing syntax errors, aggregate/non-aggregate mixing, and other common calculation bugs in Tableau.
What Is a Calculated Field?
A calculated field is a custom formula you write inside Tableau to create new data columns, transform existing data, or perform computations. They use Tableau's own formula language with functions like IF, SUM, DATEPART, and more.
Why Debugging Matters
The Three Error Families
The Core Rule: Aggregate vs Non-Aggregate
Tableau's calculation engine operates at two levels of detail. Every expression inside a formula is either an aggregate (operates on groups of rows) or a non-aggregate (operates on individual rows). You cannot mix them in the same expression without wrapping one level inside the other.
How Granularity Works
Dimensions vs Measures in Calculations
| Dimensions | Measures | |
|---|---|---|
| Default behavior | Non-aggregate (row-level) | Aggregated (SUM by default) |
| Role in viz | Defines groups/categories | Provides values to display |
| In a calc | Used directly: [Region] | Wrap in agg: SUM([Sales]) |
| Mixing risk | Safe with other dimensions | Unsafe if mixed with raw dims |
Spotting Syntax Errors
Syntax errors are the most common and easiest to fix. The Tableau calculation editor underlines the error in red and shows a message at the bottom. Here are the top culprits:
Example: Fixing a Syntax Error
ELSEIF [Category] = "Technology"
"Medium"
ELSE "Low"
ELSEIF [Category] = "Technology" THEN "Medium"
ELSE "Low"
END
The Mixing Error Explained
// Error: Cannot mix aggregate and // non-aggregate arguments
Why? SUM([Sales]) collapses many rows into one total. But [Quantity] is a raw row-level value: which row's quantity should Tableau use? There's no way to decide, so Tableau rejects the formula.
SUM([Sales]) / SUM([Quantity])
// Fix 2: Keep both non-aggregate
[Sales] / [Quantity]
Debugging Checklist
Example 1: IF Statement Repair
"Profitable"
ELSE
"Not Profitable"
"Profitable"
ELSE
"Not Profitable"
END
Example 2: Aggregate Mixing in IF
SUM([Sales]) * 1.1
ELSE
[Sales] * 1.05
END
SUM([Sales]) * 1.1
ELSE
SUM([Sales]) * 1.05
END
Example 3: Nested Calculation Debug
[Order Date], TODAY() > 6 THEN
"Old"
ELSE "Recent"
END
[Order Date], TODAY()) > 6 THEN
"Old"
ELSE "Recent"
END
Common Mistakes
Error Type Summary
| Syntax | Agg Mixing | Logic | |
|---|---|---|---|
| Detected by editor? | Yes | Yes | No |
| Error message? | Red underline | Explicit message | None |
| Difficulty to fix | Easy | Medium | Hard |
| Fix strategy | Read message, check spelling | Match agg levels | Test on text table |
| Example | Missing END | SUM + raw field | Wrong IF branch |
Question 1 of 5
Which of the following will cause an aggregate/non-aggregate mixing error?
Question 2 of 5
What is missing from this calculation?
IF [Profit] > 0 THEN "Gain" ELSE "Loss"
Question 3 of 5
In Tableau, which type of quote is used for string literals?
Question 4 of 5
You have this formula: IF ATTR([Region]) = "West" THEN SUM([Sales]) END. What does ATTR() do here?
Question 5 of 5
A student writes the following Tableau calculation to categorize orders by size:
IF SUM([Quantity]) > 100 THEN "Large"
ELSEIF SUM([Quantity]) > 50 "Medium"
ELSE "Small"
The calculation editor shows a red error underline on the second line.
What is the primary syntax error in this calculation?