TABLEAU • CALCULATIONS AND METRICS

Table Calculations: Running Totals & Averages — Create running totals, moving averages, and percent of total

Transform raw data into cumulative insights using Tableau's powerful in-memory table calculation engine.

Historical Context & Motivation

The notion of computing cumulative sums and moving averages long predates modern data visualization software. Statisticians and actuaries in the nineteenth century relied on running totals to track insurance liabilities, and economists employed moving averages to smooth out noisy time-series data such as commodity prices and stock indices. These techniques were calculated by hand in ledgers and later in spreadsheets, making them both tedious and error-prone. The advent of interactive analytics tools like Tableau fundamentally changed how analysts access these computations—transforming multi-step manual procedures into drag-and-drop operations that execute in real time against in-memory data.

For computer science students, understanding table calculations is particularly relevant because they expose a computation model that differs from traditional SQL aggregation. While SQL's GROUP BY produces one result per group, table calculations operate on a result set that has already been aggregated—analogous to window functions in SQL or map-reduce post-processing pipelines. They partition and address rows in the visual layout itself, creating a secondary computation layer that is both expressive and performance-efficient.

1901
Moving Averages in Economics
Economists formalize the simple moving average (SMA) for smoothing cyclical fluctuations in trade data, establishing a technique that remains central to time-series analysis.
1979
VisiCalc & Spreadsheet Era
The first electronic spreadsheet enables running totals via cell-reference formulas, democratizing cumulative calculations beyond statisticians and accountants.
2003
SQL Window Functions (SQL:2003)
The SQL standard introduces analytic window functions such as SUM() OVER (ORDER BY ...), allowing running totals and moving averages directly in relational queries.
2008
Tableau's Table Calculations
Tableau introduces quick table calculations, letting analysts create running totals, percent of total, and moving averages without writing code—bridging the gap between visual analytics and computational power.
2020s
LOD Expressions & Hybrid Pipelines
Modern Tableau integrates Level of Detail (LOD) expressions alongside table calculations, enabling multi-stage analytical pipelines that rival custom Python or R scripts in sophistication.

The central question that table calculations address is deceptively simple: how do you compute values that depend on other rows in a visualization without sending a new query back to the database? Running totals, moving averages, and percent-of-total computations all require awareness of neighboring or total values—something a single aggregated cell cannot provide on its own. Table calculations solve this by operating entirely within Tableau's in-memory query results, leveraging the visual layout to define ordering and partitioning.

Core Principles & Definitions

Before diving into specific calculation types, it is essential to understand the architectural foundations of Tableau's table calculation engine. Every table calculation depends on two orthogonal concepts: the partitioning of the data and the addressing (or direction) along which the calculation traverses. Together these define the scope and order of computation, much like specifying PARTITION BY and ORDER BY in a SQL window function. Mastering these twin concepts is the prerequisite for every table calculation variant covered in this lesson.

1

Partitioning

Defines the independent groups within which a table calculation resets. Equivalent to PARTITION BY in SQL. A running total partitioned by Category restarts at zero for each category.
2

Addressing (Direction)

Specifies the dimension(s) along which the calculation moves—Table (Across), Table (Down), or a custom Specific Dimensions configuration. This determines row traversal order.
3

Running Total

Computes a cumulative aggregate (sum, average, min, max) across addressed marks. Each successive mark includes all preceding values in its partition. Formally: RT(i) = Σ v(k) for k = 1 to i.
4

Moving Average

Averages a sliding window of n preceding (and optionally following) values. Smooths volatility while preserving trend information. Window size is configurable via the calculation dialog.
5

Percent of Total

Expresses each mark's value as a fraction of the partition total. Useful for composition analysis. Formally: PoT(i) = v(i) / Σ v(k) × 100%. Scope depends on partitioning choice.
KEY TAKEAWAY
Think of partitioning and addressing like iterating through a 2D array in code. Partitioning is the outer loop—it groups rows and resets state between groups. Addressing is the inner loop—it defines the traversal order within each group. A running total is simply an accumulator variable inside the inner loop; a moving average is a fixed-size sliding window buffer; and percent of total is a normalization pass that divides each element by the group's sum.
⚠️ Table Calcs vs. LOD Expressions
A common source of confusion: LOD expressions (FIXED, INCLUDE, EXCLUDE) alter the granularity of aggregation at query time, while table calculations operate post-aggregation on the rendered result set. If you need a running total that appears in tooltips and is independent of the current view dimensions, you likely need a table calculation. If you need a pre-aggregated benchmark value, use an LOD expression.

Visual Explanation

The following diagram illustrates the computation pipeline for table calculations in Tableau. Data flows from the source through Tableau's query engine, which produces an aggregated result set. Table calculations then operate on this result set—partitioning and addressing marks according to user-specified dimensions—before the final visualization is rendered. Notice that the table calculation phase sits entirely after aggregation but before rendering, which is why they cannot change the granularity of the view.

The top section shows the computation pipeline: data flows from the source through aggregation, then table calculations (running sum, window average, percent of total) are applied in-memory before rendering. The bottom chart shows monthly sales bars (purple) alongside the running total line (cyan), which monotonically increases as each month's value is accumulated.

Observe how the running total line in the diagram never decreases—this is because all monthly sales values are positive. In general, a running sum is monotonically non-decreasing only when all input values are non-negative. This is a key consideration when applying running totals to datasets that include refunds, credits, or other negative adjustments. The cyan line also demonstrates prefix-sum semantics, a concept familiar from algorithms courses: the value at position i equals the sum of all values from position 1 through i.

Mathematical Framework

Each of the three table calculation types covered in this lesson can be expressed formally. Understanding the underlying mathematics helps you reason about edge cases—such as what happens at the boundaries of a partition, how window sizes affect smoothing, and how the denominator changes in percent-of-total calculations when filters are applied.

RUNNING TOTAL (CUMULATIVE SUM)
RT(i) = Σₖ₌₁ⁱ v(k)
Where v(k) is the aggregated measure value at position k within the partition, and i is the current position along the addressing direction. This is equivalent to the prefix-sum array computed in O(n) time.
SIMPLE MOVING AVERAGE (SMA)
SMA(i, w) = (1/w) × Σₖ₌ᵢ₋ᵥ₊₁ⁱ v(k)
Where w is the window size (number of trailing values including the current one). For the first (w − 1) positions, the window shrinks to fit the available data unless null-handling rules override. In Tableau, this is implemented via WINDOW_AVG(SUM([Sales]), -2, 0) for a trailing 3-period SMA.
PERCENT OF TOTAL
PoT(i) = v(i) / Σₖ₌₁ⁿ v(k) × 100%
Where n is the total number of marks in the partition. The denominator is the grand total within the partition scope. In Tableau: SUM([Sales]) / TOTAL(SUM([Sales])). Adjusting the partition (e.g., per-pane vs. per-table) changes the denominator and thus the resulting percentages.
WINDOW SUM (GENERALIZED)
WS(i, a, b) = Σₖ₌ᵢ₊ₐⁱ⁺ᵇ v(k)
A general form where a and b are offsets relative to the current position i. For a trailing window: a < 0, b = 0. For centered: a < 0, b > 0. For TOTAL (entire partition): a = FIRST(), b = LAST(). This is the building block for all Tableau window functions.
🔍 Computational Complexity Note
From an algorithms perspective, RUNNING_SUM is a single-pass O(n) prefix sum. WINDOW_AVG with a fixed window of size w is also O(n) using a sliding window (dequeue pattern). Percent-of-total requires an initial O(n) pass to compute the denominator followed by an O(n) normalization pass. All three execute in linear time relative to the partition size, which is why Tableau's in-memory engine handles them efficiently even on large result sets.

Addressing & Scope in Detail

The behavior of every table calculation is fundamentally determined by how you configure Compute Using in Tableau. This setting controls both the addressing direction and the partition boundaries. Tableau offers several presets—Table (Across), Table (Down), Table (Across then Down), Pane (Across), Pane (Down), and Cell—as well as a fully customizable Specific Dimensions option that grants fine-grained control. Choosing the wrong scope is the single most common source of unexpected results in table calculations.

Top: side-by-side grids showing a running total computed across (left, amber) versus down (right, cyan). The highlighted first row/column shows the accumulation path. Bottom: percent-of-total computed with different partition scopes yields drastically different percentages.

The diagram above underscores a critical insight: the same raw data and the same running total function produce entirely different results depending on the addressing direction. In the left grid, the running total for East accumulates across Q1 → Q2 → Q3 → Q4, yielding 10, 30, 55, 90. In the right grid, the running total for Q1 accumulates down East → West → South, yielding 10, 25, 33. Similarly, percent-of-total yields 10% when the denominator is the row total (100) but only 2.6% when the denominator is the grand total (380). This is why Tableau practitioners must always verify the Compute Using setting before trusting the output of any table calculation.

  • Table (Across): Addresses columns left-to-right within each row. Partitions by the row dimension. Ideal for quarterly running totals within each region.
  • Table (Down): Addresses rows top-to-bottom within each column. Partitions by the column dimension. Useful for cumulative comparisons across categories for a fixed time period.
  • Pane (Across/Down): Restricts addressing to a single pane (sub-grid) when multiple dimensions create a matrix of panes. The calculation resets at each pane boundary.
  • Specific Dimensions: The most flexible option. You explicitly choose which dimensions to address and which to partition. This is equivalent to writing a custom PARTITION BY / ORDER BY clause.

Worked Example: Sales Dashboard with Three Calculations

Consider a dataset with monthly sales for two product categories—Furniture and Technology—over the first six months of 2024. We will construct a running total, a 3-month moving average, and a percent-of-total calculation, demonstrating both the Tableau interface steps and the underlying arithmetic.

Raw monthly sales data
MonthFurnitureTechnology
Jan$12,000$18,000
Feb$15,000$22,000
Mar$9,000$25,000
Apr$20,000$19,000
May$17,000$28,000
Jun$14,000$30,000
Running Total of Furniture Sales
1
Step 1 — Place fields on the shelfDrag Month to Columns and SUM(Sales) to Rows. Filter to Category = Furniture. You now see a simple bar chart with monthly aggregated values.
2
Step 2 — Add Quick Table CalculationRight-click the SUM(Sales) pill on the Rows shelf → Quick Table Calculation → Running Total. Tableau wraps your measure in RUNNING_SUM(SUM([Sales])) and computes across months (the default addressing for a single-dimension view).
3
Step 3 — Verify the arithmeticJan: 12,000. Feb: 12,000 + 15,000 = 27,000. Mar: 27,000 + 9,000 = 36,000. Apr: 36,000 + 20,000 = 56,000. May: 56,000 + 17,000 = 73,000. Jun: 73,000 + 14,000 = 87,000.
Running total at June = $87,000
3-Month Moving Average of Technology Sales
1
Step 1 — Create the calculated fieldOpen Analysis → Create Calculated Field. Enter: WINDOW_AVG(SUM([Sales]), -2, 0). The offset -2 means 'start 2 positions before the current mark,' and 0 means 'end at the current mark,' giving a window of 3 periods.
2
Step 2 — Compute for each monthJan (only 1 value available): 18,000 / 1 = 18,000. Feb (2 values): (18,000 + 22,000) / 2 = 20,000. Mar: (18,000 + 22,000 + 25,000) / 3 = 21,667. Apr: (22,000 + 25,000 + 19,000) / 3 = 22,000. May: (25,000 + 19,000 + 28,000) / 3 = 24,000. Jun: (19,000 + 28,000 + 30,000) / 3 = 25,667.
3-month MA at June ≈ $25,667
3
Step 3 — Interpret the smoothing effectThe raw Technology sales dip in April ($19K) but the moving average only drops slightly to $22K, demonstrating the volatility-dampening property. The moving average lags behind sharp changes—a characteristic well-known in signal processing.
Percent of Total Across Both Categories
1
Step 1 — Set up the viewPlace Category on Color and Month on Columns with SUM(Sales) on Rows. This creates a side-by-side bar chart.
2
Step 2 — Apply Percent of TotalRight-click SUM(Sales) → Quick Table Calculation → Percent of Total. Set 'Compute Using' to Category. Now each month's bars show the share of each category.
3
Step 3 — Calculate January as an exampleTotal for Jan = 12,000 + 18,000 = 30,000. Furniture share = 12,000 / 30,000 × 100% = 40%. Technology share = 18,000 / 30,000 × 100% = 60%.
Jan Furniture = 40%, Jan Technology = 60%

Strengths, Limitations & Comparisons

Table calculations are a powerful feature, but they are not universally the right tool for every analytical task. Understanding their strengths and limitations allows you to choose between table calculations, LOD expressions, and native SQL window functions depending on the performance characteristics and functional requirements of your dashboard.

Table Calculations: Strengths vs. Limitations
AspectStrengthsLimitations
PerformanceComputed in-memory on the already-aggregated result set. No additional database queries. O(n) complexity for all three calculation types.If the result set is very large (millions of marks), in-memory computation can be slow. Reducing mark count via filtering or aggregation before the table calc is advisable.
Ease of UseQuick Table Calculations require no coding—two right-clicks. Excellent for exploratory analysis and rapid prototyping.The Compute Using dialog can be confusing, especially with multiple dimensions. Results may silently change when fields are added or removed from the view.
FlexibilityWINDOW_SUM, WINDOW_AVG, RUNNING_SUM, INDEX, FIRST, LAST, LOOKUP, SIZE, and TOTAL provide a rich functional vocabulary for secondary computations.Cannot change the granularity of the underlying query. If you need a fixed-granularity calculation regardless of the view, use FIXED LOD expressions instead.
ComposabilityTable calculations can reference other table calculations (nested), enabling multi-pass analytics such as 'running total of percent change.'Nested table calculations can become difficult to debug. The order of operations (filters, table calcs, LODs) must be well understood to avoid subtle bugs.
PortabilityTableau-native: works identically across any data source (SQL, flat files, cloud connectors) since computation happens post-query.Table calculation logic is embedded in the workbook, not the data layer. If the same logic is needed in SQL reports or Python scripts, it must be re-implemented.
⚖️ WHEN TO USE WHAT
Use table calculations when you need computations that depend on the visual layout—running totals along a time axis, rank within a sorted bar chart, or moving averages across a line chart. Use LOD expressions when you need a value computed at a fixed granularity regardless of what's in the view (e.g., customer lifetime value). Use SQL window functions when performance demands pushing computation to the database or when the logic must be shared with non-Tableau consumers.

Connection to Advanced Theory & SQL Window Functions

Tableau's table calculations are conceptually equivalent to SQL analytic (window) functions introduced in the SQL:2003 standard. For computer science students, recognizing this correspondence is valuable because it allows you to reason about Tableau calculations using the formal semantics of SQL, and vice versa. Moreover, advanced Tableau use cases—such as computing exponentially weighted moving averages or custom ranking algorithms—require the same algorithmic thinking you would apply when writing a window function in a production data pipeline.

Tableau Table Calculations vs. SQL Window Functions
Tableau Table CalcSQL Window Function EquivalentNotes
RUNNING_SUM(SUM([Sales]))SUM(Sales) OVER (PARTITION BY region ORDER BY month ROWS UNBOUNDED PRECEDING)UNBOUNDED PRECEDING matches Tableau's default cumulative behavior from first to current mark.
WINDOW_AVG(SUM([Sales]), -2, 0)AVG(Sales) OVER (ORDER BY month ROWS BETWEEN 2 PRECEDING AND CURRENT ROW)Both define a trailing 3-period window. SQL handles edge cases (partial windows) identically.
SUM([Sales]) / TOTAL(SUM([Sales]))Sales / SUM(Sales) OVER (PARTITION BY region)TOTAL() in Tableau corresponds to a window with no ORDER BY, covering the entire partition.
INDEX()ROW_NUMBER() OVER (ORDER BY month)Returns the 1-based position of the current mark within the partition.

Beyond the direct SQL mapping, advanced users can compose table calculations to implement algorithms that would otherwise require procedural code. For example, an exponentially weighted moving average (EWMA) can be approximated using nested PREVIOUS_VALUE() calls, since EWMA(i) = α × v(i) + (1 − α) × EWMA(i − 1). This recursive formulation maps directly to Tableau's PREVIOUS_VALUE(SUM([Sales])) function. Similarly, cumulative distribution functions, percentile ranks, and even simple state machines can be implemented through creative use of LOOKUP(), FIRST(), and LAST() functions.

🚀 Looking Ahead
As you advance in Tableau, you will encounter scenarios where table calculations and LOD expressions must be combined. For instance, computing the running total of each customer's deviation from their FIXED average requires an LOD expression for the baseline and a table calculation for the cumulative sum. Mastering the order of operations in Tableau's query pipeline—Extract Filters → Data Source Filters → Context Filters → FIXED LODs → Dimension Filters → INCLUDE/EXCLUDE LODs → Measures → Table Calculations → Table Calc Filters—is essential for building reliable, complex dashboards.

Practice Problems

PROBLEM 1CONCEPTUAL
Explain the difference between partitioning and addressing in Tableau table calculations. If a crosstab has Region on rows and Quarter on columns, describe what happens when you apply a running total with 'Compute Using: Table (Across)' versus 'Table (Down).'
PROBLEM 2BASIC CALCULATION
Given monthly profit values of $5K, $8K, $3K, $10K, $6K for Jan–May, compute the running total at each month and the percent-of-total for March. Assume a single partition covering all months.
PROBLEM 3INTERMEDIATE
You have the following quarterly revenue: Q1 = $120K, Q2 = $95K, Q3 = $140K, Q4 = $110K, Q5 = $130K, Q6 = $150K. Write the Tableau calculated field expression for a centered 3-quarter moving average (1 preceding, current, 1 following). Compute the value at Q3 and explain what happens at Q1 and Q6.
PROBLEM 4APPLIED
A product manager asks you to build a Tableau dashboard showing daily order counts with a 7-day trailing moving average, plus a running total of orders year-to-date, partitioned by product category. Describe (a) the calculated fields you would create, (b) how you would configure Compute Using for each, and (c) how adding a category filter would affect the percent-of-total calculation for each category.
PROBLEM 5CRITICAL THINKING
Prove that for a partition of n non-negative values, a running-sum table calculation produces a monotonically non-decreasing sequence. Then consider: if you apply a running sum to a percent-of-total calculation (i.e., a running sum of the percent-of-total values), what will the final value in the partition always equal, and why? What computational pattern does this correspond to in algorithm design?

Lesson Summary

Tableau's table calculations operate on the post-aggregation result set, providing a secondary computation layer that transforms raw aggregates into cumulative and comparative metrics. The three core types covered—running totals (prefix sums that accumulate values across addressed marks), moving averages (sliding-window means that smooth volatility), and percent of total (normalization against the partition sum)—each leverage the same underlying framework of partitioning and addressing to define scope and traversal order.

The Compute Using setting is the single most critical configuration choice—it determines whether a running total accumulates across columns or down rows, and whether percent of total uses a row total or grand total as its denominator. Formally, these calculations map directly to SQL window functions (SUM OVER, AVG OVER with ROWS BETWEEN clauses), making the concepts transferable to any analytical SQL environment. All three table calculation types execute in O(n) time relative to the partition size, ensuring efficient performance even on sizable result sets.

Varsity Tutors • Tableau • Table Calculations: Running Totals & Averages