How to Use WINDOW SUM in Tableau

Cody Schneider7 min read

Performing calculations across multiple rows of data, like creating a running total or a moving average, is a common task in data analysis. In Tableau, the secret to this is a powerful table calculation function called WINDOW_SUM. This guide will walk you through exactly what WINDOW_SUM is, how it works, and how to use it in your own dashboards with practical, step-by-step examples.

GraphedGraphed

Your AI Data Analyst to Create Live Dashboards

Connect your data sources and let AI build beautiful, real-time dashboards for you in seconds.

Watch Graphed demo video

First, What Are Table Calculations?

Before diving into WINDOW_SUM, it’s helpful to understand what a "table calculation" is. In Tableau, most calculations happen at the row level of your underlying data source. Table calculations are different because they operate only on the data currently in your visualization - the "table" of aggregated data you see on your screen.

Think of it this way: a regular SUM([Sales]) calculation sums up all the sales in your data source based on how you’ve grouped it. A table calculation, like WINDOW_SUM(SUM([Sales])), performs its calculation across the rows or columns of your visualized table, allowing you to compare, rank, or total values within the context of the view.

Free PDF Guide

AI for Data Analysis Crash Course

Learn how to get AI to do data analysis for you — the best tools, prompts, and workflows to go from raw data to insights without writing a single line of code.

Understanding the WINDOW_SUM Function Syntax

At its core, WINDOW_SUM calculates the sum of an expression over a "window" of data. This window is a specific range of rows relative to the current row in your visualization.

The syntax looks like this:

WINDOW_SUM(expression, [start], [end])

Let's break down each part:

  • expression: This is the value you want to sum across the window. It's almost always an aggregated measure, like SUM([Sales]) or AVG([Profit]).
  • [start] (optional): This tells Tableau where the calculation window begins, relative to the current row.
  • [end] (optional): This tells Tableau where the window ends, also relative to the current row.

The start and end arguments are what make this function so flexible. You define them using offsets from the current row (represented as 0). Here are the key terms:

  • 0: The current row.
  • Integer offsets: Negative numbers refer to rows before the current one (e.g., -2 means two rows before), and positive numbers refer to rows after (e.g., 1 means one row after).
  • FIRST(): Represents the offset of the first row in the partition. So, using FIRST() as the start means your window starts at the very beginning of your dataset.
  • LAST(): Represents the offset of the last row in the partition. Using this as the end means your window extends to the end of the data.

If you leave start and end blank, Tableau defaults to using the entire partition (every row in the specific calculation scope), so it would be the same as writing WINDOW_SUM(expression, FIRST(), LAST()).

Example 1: Creating a Year-to-Date Running Total

The most common use for WINDOW_SUM is to calculate a running total. Let’s say you want to see how your monthly sales accumulate throughout the year.

Step 1: Set Up the Basic View

  1. Connect to your data source (we’ll use the Sample - Superstore dataset included with Tableau).
  2. Drag Order Date to the Columns shelf. Right-click it and choose Month (May 2015) to get a continuous monthly axis.
  3. Drag Sales to the Rows shelf. You should now see a simple line chart of sales over time.

Your chart displays the sales for each individual month, but it doesn't show the cumulative growth.

Step 2: Write the WINDOW_SUM Calculation

  1. Click the dropdown arrow in the top right of the Data pane and select Create Calculated Field.
  2. Name your calculation something clear, like "Running Total of Sales."
  3. In the formula box, type:

WINDOW_SUM(SUM([Sales]), FIRST(), 0)

This formula tells Tableau: "For each data point (each month), sum up the SUM([Sales]) for every row from the very FIRST() row up to the current row (0)."

Step 3: Add the Calculation to the View

  1. Drag your new "Running Total of Sales" calculation from the Data pane onto the Rows shelf, next to SUM(Sales).
  2. To make it easier to see, right-click the "Running Total of Sales" pill on the Rows shelf, and select Dual Axis.
  3. Finally, right-click the secondary axis on the right side of your chart and select Synchronize Axis.

You now have two lines: one for monthly sales and another showing the cumulative sum, which climbs throughout the year. The calculation naturally resets for each new pane (in this case, each year in the view).

GraphedGraphed

Your AI Data Analyst to Create Live Dashboards

Connect your data sources and let AI build beautiful, real-time dashboards for you in seconds.

Watch Graphed demo video

Example 2: Calculating a 3-Month Moving Average

Let's try another common use case: a moving average. Moving averages are great for smoothing out short-term fluctuations in data to see the underlying trend more clearly. A 3-month moving average shows the average sales over the current month and the previous two months.

Step 1: Create the Moving Sum

A moving average is just a moving sum divided by the number of periods in your window. We'll start with the sum.

  1. Using the same chart as before, create a new calculated field. Name it "3-Month Moving Sum."
  2. For the formula, use:

WINDOW_SUM(SUM([Sales]), -2, 0)

Here, the start argument, -2, tells Tableau to begin the window two rows before the current one. The end argument, 0, tells it to end on the current row. This creates a "sliding" window that always includes three values: the previous two months and the current month.

Step 2: Create the Moving Average Calculation

Now, just divide that moving sum by 3.

  1. Create another calculated field named "3-Month Moving Average."
  2. Type this simple formula:

[3-Month Moving Sum] / 3

You could also combine this into one formula: WINDOW_SUM(SUM([Sales]), -2, 0) / 3

  1. Drag this new "3-Month Moving Average" field onto the chart to see the smoothed trend line.

Free PDF Guide

AI for Data Analysis Crash Course

Learn how to get AI to do data analysis for you — the best tools, prompts, and workflows to go from raw data to insights without writing a single line of code.

Refining Your Calculation with "Compute Using"

When you use a table calculation, Tableau needs to know the scope and direction to apply it. The "Compute Using" setting controls this. You'll access it by clicking the dropdown arrow on your table calculation pill in the view.

Here’s what the most common settings mean:

  • Table (Across): Calculates across the columns for each row.
  • Table (Down): Calculates down the rows for each column.
  • Pane (Across/Down): Behaves like Table (Across/Down) but restarts the calculation for every new pane in your visualization. For example, if you have Year and Quarter in your view, a calculation computing by Pane would reset for each new Year.
  • Cell: Calculates only within a single cell, which is rarely used for WINDOW_SUM.
  • Specific Dimensions: This is the most powerful option. It lets you specify which dimension(s) define the window (addressing) and which define the partitions where the calculation should restart (partitioning).

For something like a running total of monthly sales by year, your default Pane (Across) often works fine, as it naturally restarts the WINDOW_SUM calculation every January. But if your view is more complex, you may need to explicitly tell Tableau to compute using Order Date so it calculates chronologically and partitions by another dimension, like Category.

Final Thoughts

Tableau's WINDOW_SUM function might seem tricky at first, but it's an incredibly useful tool for creating insightful calculations like running totals and moving averages. The key is understanding how to define your "window" with the start and end offsets and then directing the calculation correctly with the "Compute Using" settings. With some practice, you'll be able to quickly add another layer of analysis to your dashboards.

While mastering tools like Tableau is rewarding, it often involves a steep learning curve and constant referencing of function syntax. As we've seen, this process of learning a BI tool can often take precious time away from the real goal: finding answers. At Graphed, we’ve made analysis much simpler. Instead of writing formulas, you can connect your data sources and create reports using everyday language. For example, you can just ask, "Show me a running total of our daily sales for the last 90 days," and we'll instantly generate the chart for you, keeping everything automatically updated so you can focus on making decisions - not building reports.

Related Articles