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
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:
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.
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:
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.
The start and end arguments can initially seem confusing. However, they become easier to understand when you consider the current row as position zero.
Here is how different offset combinations work:
| Offset syntax | What it tells Tableau to include | Best use case |
| FIRST(), 0 | First row through the current row | Cumulative calculations |
| -2, 0 | Two previous rows and the current row | Three-month moving average |
| -1, 1 | Previous row, current row and next row | Centered trend analysis |
| FIRST(), LAST() | Entire partition | Calculating totals across a partition |
| 0, LAST() | Current row through the last row | Forward-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
Tableau provides several window functions for different analytical requirements. Some of the most useful ones include:
| Function | What it does | Common use case |
| WINDOW_SUM() | Calculates the sum within a specified window | Rolling sales totals |
| WINDOW_AVG() | Calculates the average within a window | Moving averages |
| WINDOW_MIN() | Returns the minimum value | Identifying lowest-performing periods |
| WINDOW_MAX() | Returns the maximum value | Identifying peak performance |
| WINDOW_MEDIAN() | Returns the median value | Analyzing data with outliers |
| WINDOW_COUNT() | Counts values within a window | Counting available records |
| WINDOW_PERCENTILE() | Returns a specified percentile | Identifying performance thresholds |
| WINDOW_STDEV() | Calculates sample standard deviation | Measuring variation |
| WINDOW_STDEVP() | Calculates population standard deviation | Measuring population variation |
| WINDOW_VAR() | Calculates sample variance | Analyzing data variability |
| WINDOW_VARP() | Calculates population variance | Measuring population variability |
| WINDOW_CORR() | Calculates correlation between two expressions | Comparing sales and profit trends |
| WINDOW_COVAR() | Calculates sample covariance | Measuring how two variables change together |
| WINDOW_COVARP() | Calculates population covariance | Measuring 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.
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.
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.
In Tableau, create a calculated field named 3-Month Moving Avg Sales and enter the following formula:
| WINDOW_AVG(SUM([Sales]), -2, 0) |
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.
Consider the following illustrative monthly sales dataset:
| Month | SUM(Sales) | Rows included | 3-Month Moving Average |
| Jan | $10,000 | Jan | $10,000 |
| Feb | $14,000 | Jan, Feb | $12,000 |
| Mar | $18,000 | Jan, Feb, Mar | $14,000 |
| Apr | $12,000 | Feb, Mar, Apr | $14,667 |
| May | $21,000 | Mar, 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.
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.
Create a calculated field named % of Regional Sales and enter:
| SUM([Sales]) / WINDOW_SUM(SUM([Sales])) |
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.
The following illustrative dataset shows how regional sales share is calculated:
| Region | Category | Sales | Regional Total | Sales Share |
| West | Technology | $250,000 | $600,000 | 41.67% |
| West | Furniture | $200,000 | $600,000 | 33.33% |
| West | Office Supplies | $150,000 | $600,000 | 25.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
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:
| Feature | Tableau Window Functions | LOD Expressions (FIXED) |
| Calculation type | Table calculations | Level of Detail calculations |
| Calculation timing | After the underlying view has been aggregated | FIXED calculations are evaluated before dimension filters |
| View dependency | Depends on the dimensions and marks in the visualization | Independent of the dimensions displayed in the view |
| Row-by-row offsets | Supports relative row calculations | Does not provide the same row-offset functionality |
| Moving averages | Supported | Not directly supported through ordinary FIXED expressions |
| Filter behaviour | Uses the data available to the table calculation | FIXED calculations generally ignore ordinary dimension filters unless context filters are used |
| Common use case | Moving averages, rolling totals and comparisons | Calculating 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:
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:
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:
| Option | Meaning |
| 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 Dimensions | Allows 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?
Even experienced Tableau users can encounter unexpected results when working with table calculations. Here are some common mistakes and how to avoid them.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
Yes. Tableau window functions can work with other dimensions, such as Region, Category, Customer Name, or Product, provided the table calculation is configured correctly.