How to Calculate Moving Average in Tableau
Calculating a moving average in Tableau is one of the quickest ways to separate the signal from the noise in your data. It helps you smooth out volatile fluctuations to reveal the underlying trend in metrics like sales, website traffic, or leads. This tutorial will walk you through exactly how to add, customize, and visualize moving averages in your Tableau worksheets.
What is a Moving Average and Why Is It Useful?
A moving average, also called a rolling average, is a calculation used to analyze data points by creating a series of averages of different subsets of the full data set. Simply put, it looks back over a specific number of previous data periods - let's say 7 days - and calculates the average. As a new day's data comes in, the oldest day is dropped, and the average "moves" forward.
Why do this? Because raw, daily data is often messy and volatile. A single high-sales day from a flash sale or a low-traffic day due to a holiday can create spikes that distort your perception of your business's health. A moving average smooths out these short-term peaks and valleys, making it much easier to spot the true long-term trend.
For example, imagine you run an e-commerce store. Your daily sales might look something like this:
- Monday: $1,200
- Tuesday: $1,500
- Wednesday: $1,300
- Thursday: $4,500 (Big promotion)
- Friday: $2,000
- Saturday: $2,500
- Sunday: $2,200
The spike on Thursday makes it hard to see what your "typical" performance is. A 7-day moving average would smooth this out, providing a clearer view of your sales momentum week over week.
How to Calculate a Moving Average in Tableau: Step-by-Step
The easiest way to get started is by using Tableau’s built-in Quick Table Calculations. Let's build a simple visualization showing sales over time and then add a moving average.
Step 1: Set Up Your Initial Line Chart
Before you can calculate a moving average, you need a time-series view. This requires a date dimension and a measure.
- Drag your date field (e.g., Order Date) onto the Columns shelf. Right-click the pill and ensure it is set to a continuous date value, such as the second "Day" option (which looks like DAY(May 8, 2015)). This ensures you get a continuous chronological axis.
- Drag your measure (e.g., Sales) onto the Rows shelf. Tableau will likely default to SUM(Sales).
You should now have a standard line chart showing your raw sales data over time. You’ll probably notice it has a lot of sharp peaks and valleys.
Step 2: Add a Quick Table Calculation
Now, let's turn this line into a moving average.
- On the Rows shelf, right-click the SUM(Sales) pill.
- In the context menu that appears, hover over Quick Table Calculation.
- From the next menu, select Moving Average.
That's it! Your line chart will instantly transform, showing a much smoother line. Tableau automatically applies a default moving average, which typically averages the current value with the previous two values. But in most cases, you'll want to customize that window.
Step 3: Customize the Moving Average Window
A 3-day window might not be meaningful for your data. Let's say you want to calculate a 7-day moving average to account for weekly patterns.
- Right-click the SUM(Sales) pill on the Rows shelf again (you'll see a small triangle icon on it, indicating a table calculation is applied).
- Select Edit Table Calculation.
- A dialog box will appear. Here, you can define exactly how your moving average works.
- Under "Moving Average," you'll see options for "Summarize values from." You can define the range using "previous values" and "next values."
- To create a 7-day trailing moving average, set it to average the previous 6 values and check the box for "Include current value." This tells Tableau to sum up the values for today and the prior six days, then divide by seven.
Click out of the dialog box, and your view will update to reflect the new 7-day window. You can play around with this value. A 30-day window will produce an even smoother line, revealing a much longer-term trend.
Visualizing Raw Data and Moving Average Together
A moving average is most insightful when viewed alongside the original data. This lets you see both the daily volatility and the underlying trend on the same chart. The best way to achieve this is with a dual-axis chart.
- First, make sure you have your moving average chart set up as described above.
- Drag the original measure (Sales) from the Data pane and drop it onto the Rows shelf again, to the right of your existing moving average pill. You'll now have two separate charts.
- On the Rows shelf, right-click the new SUM(Sales) pill (the one without the table calculation) and select Dual Axis.
- Your two line charts are now overlaid, but the axes might be misaligned. To fix this, right-click the secondary axis on the right side of your chart and select Synchronize Axis.
For better readability, you can now format each line independently using their respective Marks Cards. A great practice is to:
- Set the original SUM(Sales) Marks type to a thin, light gray line.
- Set the moving average SUM(Sales) Marks type to a thicker, boldly colored line (like blue or orange).
This formatting makes the trend line stand out as the primary focus, with the raw data providing context in the background.
Alternate Method: Using the WINDOW_AVG Function
While Quick Table Calculations are fast, they are specific to the worksheet you create them in. If you want to reuse your moving average calculation across different visualizations, it's better to create a calculated field.
Here’s how to create a 7-day moving average calculated field:
- Click the down arrow in the top right of the Data pane and select Create Calculated Field.
- Name your calculation something clear, like "7-Day Moving Avg Sales".
- Enter the following formula in the editor:
WINDOW_AVG(SUM([Sales]), -6, 0)- Click OK.
Let's break down this formula:
WINDOW_AVG(...): This is the table calculation function for averaging values within a specific window or partition.SUM([Sales]): This is the measure being aggregated and averaged.-6: This defines the start of the window. A negative number indicates an offset from the current row. So, -6 means "6 rows before the current one."0: This defines the end of the window. A 0 means "the current row."
Together, -6, 0 tells Tableau to create a window that includes the current day and the six previous days. You can now drag this new calculated field directly onto the Rows shelf to create your moving average line, without needing to perform a Quick Table Calculation each time.
Common Pitfalls and Best Practices
Choosing the Right Window Size
The "window" or period you choose for your average is critical. There's no single correct answer, it depends on your data and what you want to see.
- 7-day window: Excellent for smoothing out daily fluctuations while showing weekly performance dynamics. It effectively removes the "day of the week" effect (e.g., weekends having higher/lower sales).
- 28/30-day window: Common for revealing monthly and quarterly trends. This is useful for high-level business reporting.
- 90-day window: Use this for a bird's-eye view of your data over several months, good for identifying long-term strategic changes.
Watch Out for Data Gaps
At the very beginning of your time series, the moving average won't have enough preceding data points to calculate a full window. For a 7-day moving average, the first 6 data points will show as blank or null because there aren't 6 prior days to average with. This is normal and expected behavior.
Understanding "Compute Using"
When you edit a table calculation, you'll see a "Compute Using" option. For most time-series line charts, the default "Table (across)" is correct. This simply tells Tableau to perform the calculation chronologically from left to right across your time dimension. You only need to change this setting in more complex visualizations like matrices or stacked charts where you need to control the direction of the calculation (e.g., down, across, or pane by pane).
Final Thoughts
Mastering the moving average in Tableau is a fundamental skill that unlocks a clearer perspective on your business performance. Whether you use a Quick Table Calculation for a fast analysis or a WINDOW_AVG calculated field for a reusable metric, this technique allows you to smooth out noise and confidently identify the trends that truly matter.
Building visualizations in tools like Tableau is incredibly powerful but often requires a series of manual steps to get the insights you need. At my company, we built Graphed to remove this friction, especially for busy marketing and sales teams. Instead of clicking through menus and writing formulas, you can connect your data sources - like Google Analytics, Shopify, and Salesforce - and just ask, "Show me a 30-day moving average of my Shopify sales." We instantly build a live, interactive dashboard for you, turning hours of reporting work into a simple, 30-second task.
Related Articles
What SEO Tools Work with Google Analytics?
Discover which SEO tools integrate seamlessly with Google Analytics to provide a comprehensive view of your site's performance. Optimize your SEO strategy now!
Looker Studio vs Metabase: Which BI Tool Actually Fits Your Team?
Looker Studio and Metabase both help you turn raw data into dashboards, but they take completely different approaches. This guide breaks down where each tool fits, what they are good at, and which one matches your actual workflow.
How to Create a Photo Album in Meta Business Suite
How to create a photo album in Meta Business Suite — step-by-step guide to organizing Facebook and Instagram photos into albums for your business page.