Table Calculations in Tableau: Compute Using Is the Whole Setting
Running total, percent of total, difference from previous, rank, moving average. All five are table calculations, all five are computed on the result table rather than on the data, and all five are controlled by one setting that is easy not to notice.
What you do: set Compute Using with Specific Dimensions, every time, rather than accepting the default. It takes ten seconds and it makes the calculation say what you meant.
The short version. Ticked dimensions are the direction. Unticked dimensions are the partition it restarts on.
What a table calculation sees
Everything else in Tableau works on the data. A table calculation works on the finished table of marks: the numbers you can see on screen, arranged the way the shelves arranged them. That has two consequences worth stating plainly.
- Change the view and the calculation changes meaning, without you editing it. Drag a dimension from Rows to Columns and a running total can start running the other way.
- A dimension filter removes rows before the calculation, so filtering out January genuinely removes it from a running total. A table calculation filter, or Hide, does not.
The directions
| Setting | Runs along | Restarts at |
|---|---|---|
| Table (Across) | Every mark left to right | Each row of the table |
| Table (Down) | Every mark top to bottom | Each column |
| Pane (Across) | Left to right within a pane | Each pane, so at every outer break |
| Pane (Down) | Top to bottom within a pane | Each pane |
| Cell | Nothing. One mark. | Every mark |
| Specific Dimensions | Whatever you tick | Whatever you leave unticked |
Pane against Table is the distinction that produces most wrong numbers. With Region on Rows and Month on Columns, a running total set to Table (Across) runs straight through the region boundary and keeps accumulating. Set to Pane (Across) it restarts for each region, which is nearly always what was wanted.
Specific Dimensions, and why it is the one to use
Table and Pane are defined by the shape of the view, so moving a pill changes what they mean. Specific Dimensions names the dimensions instead, so the calculation keeps its meaning when the layout changes.
With Region and Month on the view and a running total that should run along months within each region: tick Month, leave Region unticked. Ticked is the direction, unticked is the partition. That one sentence is the whole feature.
The At the level and Restarting every options underneath matter for nested calculations, where a rank runs inside a running total. Set the outer one first, then look at the highlight again.
The five common calculations
| Calculation | Quick Table Calc name | Watch for |
|---|---|---|
| Running total | Running Total | Running through a partition boundary |
| Percent of total | Percent of Total | Adding to more than 100 across panes |
| Change from previous | Difference | The first mark being null, not zero |
| Rank | Rank | Ties, and which rank function is used |
| Moving average | Moving Average | The window including the current mark or not |
Quick Table Calculations from the right click menu are a good starting point and a poor finishing point: they apply a default Compute Using. Add one, then immediately open Edit Table Calculation and set the direction deliberately.
Writing them by hand
RUNNING_SUM(SUM([Sales]))
// difference from the previous mark, with the first one as zero
ZN(SUM([Sales]) - LOOKUP(SUM([Sales]), -1))
// share of the partition
SUM([Sales]) / TOTAL(SUM([Sales]))
// position in the partition, useful for filtering to the first n
INDEX()
ZN matters on the second one. Without it the first mark is null, and a null flowing into later arithmetic empties the chain. INDEX() is worth knowing for a different reason: filtering on it is a table calculation filter, so it hides marks without changing the running total, which is the behaviour people usually want and rarely find.
Table calculation or level of detail?
| Question | Use |
|---|---|
| Something about neighbouring marks in the view | Table calculation |
| Something at a grain that is not on the view | Level of detail expression |
| Rank of what is displayed | Table calculation |
| Each customer's first order date | {FIXED} |
| A denominator that must ignore a filter | {FIXED}, filter in context if needed |
| A denominator that must follow the view | TOTAL() table calculation |
How to apply this to your own work
- Open every table calculation in your main workbook and check its Compute Using. Convert them all to Specific Dimensions.
- Use the highlight to confirm the partition, rather than reading the numbers and hoping.
- Test each one by adding a dimension to the view. If the meaning changes, the setting was layout-dependent.
- Wrap anything that can be null in
ZNbefore it feeds arithmetic. - Where you need to hide marks without changing totals, filter on
INDEX()rather than on the dimension.
The one habit to keep
Say what the calculation runs along and where it restarts, in one sentence, before setting anything. If you cannot say it, the setting will be a guess, and it will hold until somebody moves a pill.
Would your running total survive somebody swapping Rows and Columns?
Tableau for Analysts is 110 pages on how Tableau actually thinks: dimensions against measures, relationships against joins, sets, and level of detail. Enough that you stop dragging fields until it looks right.
Tableau for Analysts, $19 →Calculated fields covers the four kinds and where table calcs sit among them, and the order of operations shows why they run last.
Read Calculated Fields →