Tableau window functions

Tableau window functions

Yash Soni
November 28th, 2026
35
5: 00 Minutes

If you have ever performed the calculations of three-month rolling averages or made comparisons between the revenue of a store and sales in the region using Tableau, you might have discovered that the regular aggregations such as SUM() or AVG() do not yield satisfying results.

Tableau window functions come to your aid in this case.

Tableau window functions can be defined as table calculations that make calculations within the range of aggregated values while leaving the values of every data point and every mark in visualization unchanged. The functions give you an opportunity to calculate rolling totals and moving averages and conduct regional comparisons.

In this blog, you will learn how to apply window functions in Tableau, how to form the syntax and the row offset and walk through examples based on a Sample - Superstore account.

Read Also: Power BI vs Tableau

What Are Tableau Window Functions?

Tableau window functions are table calculations that compute statistics across a defined range of rows (a "window") inside the current visualization. They operate on already aggregated data points, letting you calculate moving averages, sliding totals and range-based metrics without losing your view's row structure.

Think of your Tableau worksheet as a spreadsheet. A normal aggregation such as SUM([Sales]) calculates the total sales for each mark in your view. A window function such as WINDOW_SUM(SUM([Sales])) looks across a selected group of marks and calculates their combined value.

For example, you can use a window function to calculate the total sales for the current month and the two preceding months without removing the individual monthly sales values from your visualization.

Here are some reasons data analysts use Tableau window functions:

  • Dynamic analysis: They calculate results based on the data currently displayed in the visualization.
  • Flexible trend analysis: They help calculate moving averages, rolling totals and other time-based metrics.
  • Comparative analysis: They allow you to compare individual values against a larger group or partition.
  • Dashboard insights: They help identify performance trends, peak values and unusual changes in business data.

One important distinction is that Tableau window functions do not directly operate on raw database rows. They calculate over aggregated marks in the visualization. Their results therefore depend on the dimensions, measures, sorting and table calculation settings used in the view.

Understanding Tableau Window Function Syntax and Offsets

Every Tableau window function follows a specific syntax. Understanding its arguments makes it easier to create different calculations.

For example, the general syntax for a window sum is:

WINDOW_SUM(expression, [start, end])

Let's understand each component:

  • expression (Required): The aggregated field or expression on which you want to perform the calculation, such as SUM([Sales]) or AVG([Profit]).
  • start and end (Optional): These arguments define the beginning and ending positions of the calculation relative to the current row.

The exact arguments depend on the particular WINDOW function. For example, WINDOW_PERCENTILE also requires a percentile argument, while WINDOW_CORR and WINDOW_COVAR require two expressions.

How Row Offsets Work (FIRST(), LAST() and Relative Numbers)

The start and end arguments can initially seem confusing. However, they become easier to understand when you consider the current row as position zero.

  • Negative numbers (-1, -2) refer to rows before the current row.
  • Positive numbers (1, 2) refer to rows after the current row.
  • FIRST() refers to the first row in the partition.
  • LAST() refers to the last row in the partition.
  • 0 represents the current row.

Here is how different offset combinations work:

Offset syntaxWhat it tells Tableau to includeBest use case
FIRST(), 0First row through the current rowCumulative calculations
-2, 0Two previous rows and the current rowThree-month moving average
-1, 1Previous row, current row and next rowCentered trend analysis
FIRST(), LAST()Entire partitionCalculating totals across a partition
0, LAST()Current row through the last rowForward-looking calculations

Remember that FIRST() and LAST() return relative offsets within a partition. They are not simply fixed row numbers. This is why they can be used to define calculation boundaries dynamically.

Also Explore: Tableau Tutorial for Beginners

Most Useful Tableau Window Functions You Should Know

Tableau provides several window functions for different analytical requirements. Some of the most useful ones include:

FunctionWhat it doesCommon use case
WINDOW_SUM()Calculates the sum within a specified windowRolling sales totals
WINDOW_AVG()Calculates the average within a windowMoving averages
WINDOW_MIN()Returns the minimum valueIdentifying lowest-performing periods
WINDOW_MAX()Returns the maximum valueIdentifying peak performance
WINDOW_MEDIAN()Returns the median valueAnalyzing data with outliers
WINDOW_COUNT()Counts values within a windowCounting available records
WINDOW_PERCENTILE()Returns a specified percentileIdentifying performance thresholds
WINDOW_STDEV()Calculates sample standard deviationMeasuring variation
WINDOW_STDEVP()Calculates population standard deviationMeasuring population variation
WINDOW_VAR()Calculates sample varianceAnalyzing data variability
WINDOW_VARP()Calculates population varianceMeasuring population variability
WINDOW_CORR()Calculates correlation between two expressionsComparing sales and profit trends
WINDOW_COVAR()Calculates sample covarianceMeasuring how two variables change together
WINDOW_COVARP()Calculates population covarianceMeasuring covariance across a population

Note: WINDOW_COUNT() counts non-null values of the specified expression across the window. When used with an aggregated measure, it counts non-null aggregated marks rather than raw database records.

The functions above have different argument requirements. For example, WINDOW_PERCENTILE() requires a percentile value between 0 and 1, while WINDOW_CORR() requires two expressions. Always check the function-specific syntax before creating a calculated field.

Practical Examples: Tableau Window Functions in Action

Let's explore two practical business scenarios using a sample monthly retail sales dataset. These examples demonstrate how to create calculated fields, configure table calculations and interpret the results.

Example 1: Calculating a 3-Month Moving Average (WINDOW_AVG)

The Scenario: Your company's monthly sales fluctuate because of seasonal promotions and changing customer demand. Your manager wants a three-month moving average to identify the underlying sales trend.

Step 1: Create a Calculated Field

In Tableau, create a calculated field named 3-Month Moving Avg Sales and enter the following formula:

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

Step 2: Understand the Formula

The formula calculates the average sales for the current month and the two preceding months.

For example, when Tableau calculates the moving average for March, it considers January, February and March.

Step 3: Configure the Table Calculation

  1. Drag MONTH(Order Date) to Columns.
  2. Drag SUM(Sales) to Rows.
  3. Add the calculated field to the view.
  4. Right-click the calculated field and select Edit Table Calculation.
  5. Set Compute Using to the date dimension, such as Table (Across), if months are arranged horizontally.

Expected Output:

Consider the following illustrative monthly sales dataset:

MonthSUM(Sales)Rows included3-Month Moving Average
Jan$10,000Jan$10,000
Feb$14,000Jan, Feb$12,000
Mar$18,000Jan, Feb, Mar$14,000
Apr$12,000Feb, Mar, Apr$14,667
May$21,000Mar, Apr, May$17,000

The first two months use the available rows because a complete three-month window does not yet exist. If you need to display results only after three periods are available, you can add a condition to suppress incomplete windows.

The moving average smooths short-term fluctuations and makes it easier to identify changes in sales performance.

Example 2: Finding Regional Sales Share (WINDOW_SUM)

The Scenario: Your company sells products across multiple regions. You want to understand what percentage of each region's total sales comes from individual product categories.

Step 1: Create a Calculated Field

Create a calculated field named % of Regional Sales and enter:

SUM([Sales]) / WINDOW_SUM(SUM([Sales]))

Step 2: Configure Addressing and Partitioning

  1. Drag Region to Rows.
  2. Drag Category below Region on Rows.
  3. Drag SUM(Sales) to Text on the Marks card.
  4. Add the calculated field to the view.
  5. Open Edit Table Calculation and select Specific Dimensions.
  6. Select Category as the addressing dimension and leave Region unchecked so that the calculation restarts for each region.

Step 3: Understand the Formula

The numerator calculates the sales for an individual category, while the denominator calculates the total sales across the categories within the same region.

Dividing these values gives the percentage contribution of each category to its regional sales total.

Expected Output:

The following illustrative dataset shows how regional sales share is calculated:

RegionCategorySalesRegional TotalSales Share
WestTechnology$250,000$600,00041.67%
WestFurniture$200,000$600,00033.33%
WestOffice Supplies$150,000$600,00025.00%

The results help managers understand which product categories contribute the most to regional revenue.

The same calculation can be repeated for other regions, provided Region is configured as a partitioning dimension and Category is configured as an addressing dimension.

Also Explore: Tableau MCQs With Answers

Tableau Window Functions vs. LOD Expressions: Which One Should You Use?

One common question among Tableau beginners is when to use a window function instead of a Level of Detail (LOD) expression.

Both can perform calculations across groups of data, but they work differently and serve different analytical needs.

For example, you can use a window function to calculate a regional sales total based on the marks in your current view. Alternatively, you can use a FIXED LOD expression to calculate regional sales independently of the dimensions displayed in the worksheet.

Here is how they compare:

FeatureTableau Window FunctionsLOD Expressions (FIXED)
Calculation typeTable calculationsLevel of Detail calculations
Calculation timingAfter the underlying view has been aggregatedFIXED calculations are evaluated before dimension filters
View dependencyDepends on the dimensions and marks in the visualizationIndependent of the dimensions displayed in the view
Row-by-row offsetsSupports relative row calculationsDoes not provide the same row-offset functionality
Moving averagesSupportedNot directly supported through ordinary FIXED expressions
Filter behaviourUses the data available to the table calculationFIXED calculations generally ignore ordinary dimension filters unless context filters are used
Common use caseMoving averages, rolling totals and comparisonsCalculating customer-level or regional-level metrics

The important distinction is that FIXED, INCLUDE and EXCLUDE LOD expressions do not all follow identical filter behaviour. FIXED expressions are evaluated before dimension filters, whereas INCLUDE and EXCLUDE expressions are evaluated after dimension filters.

The Rule of Thumb:

  • Use window functions when your calculation depends on the order of marks, such as moving averages, rolling totals, or comparisons between rows.
  • Use FIXED LOD expressions when you need calculations at a specified level of detail, independently of the dimensions displayed in your worksheet.
  • Use INCLUDE and EXCLUDE expressions when you need to adjust the level of detail while considering the dimensions and filters in your view.

Understanding Compute Using, Addressing and Partitioning

Compute Using is one of the most important settings when working with Tableau window functions. It determines the direction in which Tableau performs the calculation and the point at which the calculation restarts.

Tableau uses two important concepts to determine how a table calculation works:

  • Addressing: Defines the dimensions along which the calculation moves.
  • Partitioning: Defines how the data is divided into separate groups. The calculation restarts for each partition.

For example, if you calculate a moving average across monthly sales, Month is generally the addressing dimension. If you want the calculation to restart for every region, Region becomes the partitioning dimension.

Here are some common Compute Using options:

OptionMeaning
Table (Across)Calculates horizontally across the table
Table (Down)Calculates vertically down the table
Table (Across then Down)Calculates across the table and then down
Pane (Across/Down)Calculates within a pane and restarts for each pane
Specific DimensionsAllows you to select the dimensions used for addressing and partitioning

The exact options and their behaviour depend on the structure of your visualization. When a worksheet contains multiple dimensions, Specific Dimensions gives you more control over how the calculation moves through the marks.

For example, if your moving average is calculated in the wrong direction, check the addressing dimension and the Compute Using setting before changing the formula.

Read Also: How to Create a Dashboard in Tableau?

Common Mistakes Beginners Make with Window Functions

Even experienced Tableau users can encounter unexpected results when working with table calculations. Here are some common mistakes and how to avoid them.

1. Forgetting to Aggregate the Expression

A window function generally requires an aggregated expression, such as:

WINDOW_AVG(SUM([Sales]))

Using an unaggregated field directly, such as WINDOW_AVG([Sales]), can result in an invalid calculation.

2. Ignoring the Compute Using Direction

Tableau needs to know whether the calculation should move across columns, down rows, or through selected dimensions.

If your dates run vertically down the Rows shelf, using Table (Across) may calculate in the wrong direction.

3. Filtering Out Data Too Early

Dimension filters are applied before table calculations. Therefore, removing January and February from a view can affect the March result of a three-month moving average.

To hide marks without removing the underlying values used in the table calculation, consider using a table calculation filter. Table calculation filters are applied after the table calculations have been evaluated.

4. Confusing Window Functions with LOD Expressions

Window functions and LOD expressions operate at different stages of Tableau's calculation process. Using one when the other is required can produce unexpected results.

Before creating a calculated field, determine whether your calculation depends on the marks in the visualization or on a specific level of detail in the underlying data.

5. Using the Wrong Window Boundaries

An incorrect start or end offset can include more or fewer rows than intended.

For example, WINDOW_AVG(SUM([Sales]), -2, 0) includes three rows when all three are available. By contrast, WINDOW_AVG(SUM([Sales]), -3, 0) includes up to four rows.

Always check the number of rows included in your calculation.

Wrapping Up

Tableau window functions make it easier to analyse trends, compare values and perform calculations across a specific range of data points. Whether you want to calculate a moving average, compare regional sales, or identify performance patterns, functions such as WINDOW_SUM(), WINDOW_AVG() and WINDOW_MAX() can help you gain deeper insights from your visualisations.

The key to using window functions effectively is understanding how Tableau handles addressing, partitioning and calculation direction. Once you understand these settings, you can build more meaningful calculations and create visualisations that support better business decisions.

Start experimenting with Tableau window functions using your own datasets to see how they can simplify complex analytical tasks and improve your data storytelling.

FAQs

1. What is the difference between SUM and WINDOW_SUM in Tableau?

SUM([Sales]) aggregates sales at the level of detail of each mark in your visualization. WINDOW_SUM(SUM([Sales])) takes those aggregated values and adds them across a specified range of rows.

2. How do I exclude the current row in a Tableau window function?

You can exclude the current row by changing the start and end offsets.

For example:

WINDOW_AVG(SUM([Sales]), -3, -1)

This calculates the average of the three preceding rows without including the current row.

3. Are Tableau window functions the same as SQL window functions?

They are conceptually similar because both perform calculations across related rows without collapsing the output into a single row.

However, SQL window functions execute within the database using the OVER() clause, while Tableau window functions are table calculations performed on the aggregated data in the visualization.

4. What is the difference between WINDOW_SUM and RUNNING_SUM?

RUNNING_SUM() calculates a cumulative total from the beginning of a partition to the current row.

WINDOW_SUM() allows you to define a specific range of rows using start and end offsets.

For example, a running sum can calculate cumulative sales from January through the current month, while a window sum can calculate sales for only the current month and the two preceding months.

5. Can I use Tableau window functions without a date field?

Yes. Tableau window functions can work with other dimensions, such as Region, Category, Customer Name, or Product, provided the table calculation is configured correctly.

About the Author
Yash Soni | igmGuru
About the Author

Yash Soni is a certified business intelligence and data analytics professional with experience across retail and finance analytics. His expertise includes data modeling, dashboard development, reporting, and KPI analysis, using tools such as Power BI, Tableau, and SQL. Apart from his job, he loves to write content so he can engage with new learners and share his knowledge with them.

Drop Us a Query
Fields marked * are mandatory
×

Your Shopping Cart


Your shopping cart is empty.