Skip to main content
Albero Academy

Calculated Fields & Table Calculations

Master row-level vs aggregate calcs, IF/CASE logic, and table calculations — running totals, % of total, rank, and moving averages.

Chapter 3Tableau14 min readBeginner friendly
  • #Tableau
  • #Calculations
  • #Table Calcs

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

KindRunsExample
Row-levelon every row of the source data[Profit] / [Sales]
Aggregateon the aggregated result in the viewSUM([Profit]) / SUM([Sales])
Table calcon the visible table in the viewWINDOW_SUM(SUM([Sales]))

Row-level calculations

Text
// Date math
DATEDIFF('day', [Order Date], [Ship Date])
// Concat strings
[First Name] + " " + [Last Name]
// Boolean flag
[Region] = "South" AND [Discount] > 0

Aggregate calculations

Text
// Profit margin — correct
SUM([Profit]) / SUM([Sales])
// Average order value
SUM([Sales]) / COUNTD([Order ID])
// Conditional aggregate
SUM(IF [Status] = "Paid" THEN [Sales] END)

IF / CASE / SWITCH

Text
// IF / ELSEIF
IF [Sales] > 1000 THEN "High"
ELSEIF [Sales] > 500 THEN "Mid"
ELSE "Low"
END
// CASE — best for equality on a single field
CASE [Region]
WHEN "North" THEN 1
WHEN "South" THEN 2
WHEN "East" THEN 3
ELSE 9
END
// IIF for short ternaries
IIF([Profit] >= 0, "Positive", "Loss")

Table calculations

Run on the rows visible in the view. The most-used:

FunctionWhat 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
Text
// Running total
RUNNING_SUM(SUM([Sales]))
// % of total — across the view
SUM([Sales]) / TOTAL(SUM([Sales]))
// 7-day moving average
WINDOW_AVG(SUM([Sales]), -6, 0)
// Difference from previous month
SUM([Sales]) - LOOKUP(SUM([Sales]), -1)

Recipes you'll reuse

1. % difference from prior period

Text
(SUM([Sales]) - LOOKUP(SUM([Sales]), -1)) / LOOKUP(SUM([Sales]), -1)

2. Rank with ties broken

Text
RANK_UNIQUE(SUM([Sales])) // each row gets a unique rank

3. Top-N filter that respects the view

Text
// Use a parameter for N, then filter on this calc
INDEX() <= [Top N parameter]

Key takeaways

  1. 01Row-level runs per source row; aggregate runs after grouping; table calcs run on the view.
  2. 02Use SUM(IF condition THEN x END) for conditional aggregates — like SQL CASE.
  3. 03Reach for table calcs (RUNNING_SUM, WINDOW_AVG, LOOKUP) for view-relative metrics.
  4. 04Compute Using direction matters — right-click → Compute Using → pick the dimension.
  5. 05Average of percentages != percentage of totals. Compute ratios at the aggregate level.