Tableau has three flavours of calculation: row-level, aggregate, and table calculations. Each runs at a different stage of the pipeline. Knowing which to reach for is the difference between code that works and code that mysteriously gives wrong totals.
Three kinds of calculations
| Kind | Runs | Example |
|---|---|---|
| Row-level | on every row of the source data | [Profit] / [Sales] |
| Aggregate | on the aggregated result in the view | SUM([Profit]) / SUM([Sales]) |
| Table calc | on the visible table in the view | WINDOW_SUM(SUM([Sales])) |
Row-level calculations
// Date mathDATEDIFF('day', [Order Date], [Ship Date])// Concat strings[First Name] + " " + [Last Name]// Boolean flag[Region] = "South" AND [Discount] > 0
Aggregate calculations
// Profit margin — correctSUM([Profit]) / SUM([Sales])// Average order valueSUM([Sales]) / COUNTD([Order ID])// Conditional aggregateSUM(IF [Status] = "Paid" THEN [Sales] END)
IF / CASE / SWITCH
// IF / ELSEIFIF [Sales] > 1000 THEN "High"ELSEIF [Sales] > 500 THEN "Mid"ELSE "Low"END// CASE — best for equality on a single fieldCASE [Region]WHEN "North" THEN 1WHEN "South" THEN 2WHEN "East" THEN 3ELSE 9END// IIF for short ternariesIIF([Profit] >= 0, "Positive", "Loss")
Table calculations
Run on the rows visible in the view. The most-used:
| Function | What it does |
|---|---|
| RUNNING_SUM(expr) | cumulative total |
| WINDOW_SUM(expr, start, end) | sliding-window sum |
| WINDOW_AVG(expr) | mean across the window |
| LOOKUP(expr, offset) | previous / next value |
| INDEX() / FIRST() / LAST() | position helpers |
| RANK() / RANK_DENSE() | rank within the partition |
// Running totalRUNNING_SUM(SUM([Sales]))// % of total — across the viewSUM([Sales]) / TOTAL(SUM([Sales]))// 7-day moving averageWINDOW_AVG(SUM([Sales]), -6, 0)// Difference from previous monthSUM([Sales]) - LOOKUP(SUM([Sales]), -1)
Recipes you'll reuse
1. % difference from prior period
(SUM([Sales]) - LOOKUP(SUM([Sales]), -1)) / LOOKUP(SUM([Sales]), -1)
2. Rank with ties broken
RANK_UNIQUE(SUM([Sales])) // each row gets a unique rank
3. Top-N filter that respects the view
// Use a parameter for N, then filter on this calcINDEX() <= [Top N parameter]
Key takeaways
- 01Row-level runs per source row; aggregate runs after grouping; table calcs run on the view.
- 02Use SUM(IF condition THEN x END) for conditional aggregates — like SQL CASE.
- 03Reach for table calcs (RUNNING_SUM, WINDOW_AVG, LOOKUP) for view-relative metrics.
- 04Compute Using direction matters — right-click → Compute Using → pick the dimension.
- 05Average of percentages != percentage of totals. Compute ratios at the aggregate level.
