3-month moving average with the WINDOW function

Average the current and two previous months with WINDOW and AVERAGEX, the row-based way to build moving averages over any sorted list.

You will learn to

  • Describe a sliding range of rows with WINDOW
  • Iterate a WINDOW result with AVERAGEX
  • Use relative (REL) start and end positions

How it works

`WINDOW` is OFFSET’s big sibling: instead of one neighboring row it returns a **range of rows**, described by where it starts and ends.

`WINDOW(from, REL, to, REL, relation, ORDERBY(…))` counts positions **relative** to the current row: `-2, REL` is two rows back and `0, REL` is the current row, so together they make a 3-row window. Swap `REL` for `ABS` and the position counts from the start of the list instead (`1, ABS` is the first row), which is how you’d build a running total.

The window is a table of months, so iterate it: `AVERAGEX(window, [Total Sales])` works out each month’s sales (the measure triggers context transition for each row) and averages them. At the start of the list the window simply holds fewer rows, so the first months average what exists, with no divide-by-3 trap.

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

Running Units (Window) = SUMX(WINDOW(1, ABS, 0, REL, ALLSELECTED('Date'[Month Year], 'Date'[YearMonth]), ORDERBY('Date'[YearMonth])), [Total Quantity])