0
0
Tableaubi_tool~10 mins

Moving average in Tableau - Cell-by-Cell Formula Trace

Choose your learning style9 modes available
Sample Data

Daily sales data for five days.

CellValue
A1Date
B1Sales
A22024-01-01
B2100
A32024-01-02
B3120
A42024-01-03
B4130
A52024-01-04
B590
A62024-01-05
B6110
Formula Trace
WINDOW_AVG(SUM([Sales]), -2, 0)
Step 1: SUM([Sales]) at 2024-01-01
Step 2: SUM([Sales]) at 2024-01-02
Step 3: SUM([Sales]) at 2024-01-03
Step 4: Calculate WINDOW_AVG for 2024-01-03 using sales from 2024-01-01 to 2024-01-03
Step 5: Calculate WINDOW_AVG for 2024-01-04 using sales from 2024-01-02 to 2024-01-04
Step 6: Calculate WINDOW_AVG for 2024-01-05 using sales from 2024-01-03 to 2024-01-05
Cell Reference Map
    A          B
1 | Date     | Sales |
2 | 2024-01-01 | 100  |
3 | 2024-01-02 | 120  |
4 | 2024-01-03 | 130  |
5 | 2024-01-04 | 90   |
6 | 2024-01-05 | 110  |

Arrows show WINDOW_AVG uses current row and two previous rows in column B (Sales).
The formula references the Sales values in column B for the current date and the two previous dates to calculate the moving average.
Result
    A          B       C
1 | Date     | Sales | Moving Avg |
2 | 2024-01-01 | 100  |           |
3 | 2024-01-02 | 120  |           |
4 | 2024-01-03 | 130  | 116.67    |
5 | 2024-01-04 | 90   | 113.33    |
6 | 2024-01-05 | 110  | 110.00    |
The Moving Avg column shows the 3-day moving average of sales, starting from the third date because the first two dates don't have two previous days to average.
Sheet Trace Quiz - 3 Questions
Test your understanding
What sales values are used to calculate the moving average on 2024-01-04?
ASales on 2024-01-02, 2024-01-03, and 2024-01-04
BSales on 2024-01-01, 2024-01-02, and 2024-01-03
CSales on 2024-01-03, 2024-01-04, and 2024-01-05
DOnly sales on 2024-01-04
Key Result
WINDOW_AVG(SUM([Measure]), -N, 0) calculates the average of the current and previous N rows.