01 / 21
Σ

Common Table
Calculations

Master LOOKUP, WINDOW_SUM, and other essential table calculations to unlock powerful analytics in Tableau.

Tableau Data Analytics

What Are Table Calculations?

Table calculations are computed locally in the visualization rather than in the data source. They transform values that Tableau has already aggregated, allowing you to compute things like running totals, percent differences, and moving averages without writing SQL or altering your data.

The Computation Pipeline

Data Source Raw rows Aggregation SUM, AVG, etc. Table Calculations LOOKUP, WINDOW_SUM... Step 1 Step 2 Step 3

Why Table Calcs Matter

No SQL Required
Perform advanced analytics without modifying your data source or writing custom queries.
Context-Aware
Results depend on the structure of your view: dimensions, sort order, and layout all influence the result.
Dynamic
Change a filter or rearrange your view, and table calculations automatically recompute on the new scope.

Core Functions Overview

LOOKUP
Returns the value of an expression in a target row at a specified offset from the current row.
WINDOW_SUM
Returns the sum of an expression across a defined window (range) of rows in the partition.
RUNNING_TOTAL
Returns a cumulative total from the start of the partition up to the current row.

LOOKUP: Referencing Other Rows

LOOKUP(expression, offset)

expression: any aggregated measure or table calculation.
offset: an integer indicating how many rows forward (positive) or backward (negative) to look. An offset of 0 returns the current row's value.

Row Month SUM(Sales) 1 Jan $12,400 2 Feb $15,800 3 Mar $18,200 ← current 4 Apr $14,600 -2

WINDOW_SUM: Summing Across a Range

WINDOW_SUM(expression, start, end)

start and end are offsets relative to the current row. Use FIRST() and LAST() to reference the partition boundaries dynamically.

100 Jan 150 Feb 200 Mar 120 Apr 180 May WINDOW_SUM = 570 current row

Addressing vs. Partitioning

Addressing
The direction the calculation moves through. Determines which marks are traversed (e.g., across months or down categories).
Partitioning
The scope within which the calculation resets. Defines independent groups (e.g., each region computes its own running total).

More Essential Functions

RUNNING_TOTAL
Cumulative sum from the start of the partition to the current row. Syntax: RUNNING_TOTAL(SUM([Sales]))
WINDOW_AVG
Average across a window of rows. Useful for moving averages: WINDOW_AVG(SUM([Sales]), -2, 0)
INDEX()
Returns the position of the current row in the partition. First row = 1, second = 2, etc. Great for ranking.
FIRST() / LAST()
Returns the offset from the current row to the first or last row in the partition. Useful for dynamic windows.

How to Apply Table Calculations

1
Build your basic view. Place dimensions and aggregated measures on shelves first.
2
Create a calculated field. Use the table calc function (LOOKUP, WINDOW_SUM, etc.) in a new calculated field.
3
Drag to the view. Place the new field on Rows, Columns, Text, or another shelf.
4
Set "Compute Using." Right-click the pill → Compute Using → choose addressing (e.g., "Table (across)" or specific dimensions).
5
Validate results. Cross-check against a simple data table view. Hover over marks to inspect the computed values.

Example 1: Running Total

Given monthly sales data, create a cumulative total that grows as you move across months.

MonthSUM(Sales)RUNNING_TOTAL
Jan$10,000$10,000
Feb$15,000$25,000
Mar$12,000$37,000
Apr$18,000$55,000
RUNNING_TOTAL(SUM([Sales]))

Example 2: LOOKUP for Period Comparison

Compare each quarter's profit to the previous quarter to find the period-over-period change.

// Current quarter profit minus previous quarter
SUM([Profit]) - LOOKUP(SUM([Profit]), -1)
QuarterSUM(Profit)LOOKUP(..., -1)Difference
Q1$8,000NULLNULL
Q2$12,000$8,000+$4,000
Q3$9,500$12,000-$2,500
Q4$14,000$9,500+$4,500

Example 3: Percent of Total

Use WINDOW_SUM to compute each category's share of the grand total.

SUM([Sales]) / WINDOW_SUM(SUM([Sales]), FIRST(), LAST())
CategorySUM(Sales)WINDOW_SUM% of Total
Technology$120K$300K40.0%
Furniture$90K$300K30.0%
Office Supplies$90K$300K30.0%

Understanding FIRST() and LAST()

Row 1 Row 2 Row 3 Row 4 Row 5 FIRST() = -2 LAST() = 2 current row

Common Mistakes

✕ Wrong "Compute Using"
The default addressing may not match your intent. Always explicitly set whether the calc runs across, down, or along a specific dimension.
✕ Ignoring NULL from LOOKUP
LOOKUP returns NULL at partition boundaries. Wrap with ZN() or IFNULL() to substitute a default value like 0.
✕ Filtering Removes Marks
Dimension filters shrink the partition before the table calc runs, changing results. Use context filters or table-calc-based filters instead.

Summary Comparison

Function Purpose Key Parameters Output
LOOKUP Reference another row expression, offset Single value
WINDOW_SUM Sum across a range expression, start, end Aggregate of window
RUNNING_TOTAL Cumulative sum expression Running aggregate
WINDOW_AVG Average across a range expression, start, end Moving average
INDEX() Row position none Integer (1, 2, 3...)
FIRST() / LAST() Offset to boundaries none Integer offset

Question 1 of 5

Table calculations in Tableau are computed:

Question 2 of 5

If you are on Row 3 of a 5-row partition, what does LOOKUP(SUM([Sales]), -2) return?

Question 3 of 5

To compute each category's share of the grand total, which formula is correct?

Question 4 of 5

In the context of table calculations, what does "partitioning" control?

Question 5 of 5

Why does LOOKUP(SUM([Profit]), -1) return NULL for the first row in a partition?