Out of the box, Tableau lets you sum, average, and group fields. To do anything analytical — margin, growth rate, segment classification, derived metrics — you write calculated fields. The syntax is its own small language: function calls, operators, IF/THEN/ELSE, aggregations. Most analyst work happens here.
Three calculations you'll write hundreds of times
// 1. Gross marginGross margin = (SUM([Revenue]) - SUM([Cost])) / SUM([Revenue])// 2. Year-over-year growth (with table calc — see Module 8)YoY growth = ([Sales] - LOOKUP([Sales], -1)) / LOOKUP([Sales], -1)// 3. Customer segment classificationSegment = IF [Annual spend] > 100000 THEN 'Enterprise'ELSEIF [Annual spend] > 10000 THEN 'Mid-market'ELSE 'SMB' END
Row-level vs aggregated
- Row-level: evaluated for every row in the underlying data. [Quantity] * [Unit Price]. Used when you need a derived value at the original grain.
- Aggregated: uses aggregation functions like SUM, AVG, MAX. SUM([Revenue]) / SUM([Cost]). Evaluated at the visualisation's level of detail.
- Mixing the two: SUM([Revenue]) / [Cost] is invalid — Tableau will error. The fix: either aggregate both or aggregate neither.
The order of operations
Tableau executes operations in a specific order: data source filters → context filters → FIXED LODs → dimension filters → INCLUDE/EXCLUDE LODs → measure filters → table calc filters → references → table calcs. If your calc gives unexpected results, it's almost always because you assumed an operation ran at a different stage than it actually did. The order-of-operations diagram is the most printed-and-pinned Tableau reference there is.
Conditional functions
- IF [x] > 10 THEN 'big' ELSEIF [x] > 5 THEN 'medium' ELSE 'small' END — the long form.
- IIF([x] > 10, 'big', 'small') — single-condition ternary.
- CASE [region] WHEN 'EA' THEN 'East Africa' WHEN 'WA' THEN 'West Africa' ELSE 'Other' END — switch syntax for discrete values.
Exercise
In a Tableau workbook, write a calculated field that classifies orders by size (Large > $1000, Medium $100-$1000, Small < $100). Drop it on Rows; put count of orders on Columns. Now add the calculation to the Tooltip with formatting. What's the level of detail of your calculation — row-level or aggregated?