3-month moving average with AVERAGEX: divide by the months you have

Average monthly sales over a rolling 3-month window with AVERAGEX and DATESINPERIOD, and avoid the divide-by-3 mistake at the start of your data.

You will learn to

  • Average a measure over the months in a rolling window
  • Explain why dividing by 3 is wrong at the edges
  • Choose the grain an average iterates over

How it works

A **moving average** smooths a bumpy line: each month shows the average of itself and the two months before it. It’s tempting to write `[Sales R3M] / 3`, and that works in the middle of the data. But January 2024 has no earlier months, so its window holds one month, and dividing by 3 makes it look like a third of what it really was.

The robust way is to **average over the months that are actually in the window**:

- `DATESINPERIOD` sets the window, inside `CALCULATE`. - Inside it, `AVERAGEX(VALUES('Date'[Month Year]), [Total Sales])` walks the visible months and averages their sales.

Mind the grain. `AVERAGEX` averages whatever rows you give it: give it months and you get an average **month**; give it dates and you get an average **day**.

Practice it hands-on with a real data model and a live report that updates as you type.

Avg Quarter Sales (Last Year) = CALCULATE(AVERAGEX(VALUES('Date'[Quarter]), [Total Sales]), DATESINPERIOD('Date'[Date], MAX('Date'[Date]), -1, YEAR))