7-day moving average of daily sales

Calculate a trailing 7-day average of daily sales with DATESINPERIOD and DIVIDE, and see why quiet days must count as zero.

You will learn to

  • Build a day-based rolling window
  • Decide whether empty periods are zeros or missing
  • Divide by calendar days rather than days with sales

How it works

A **7-day moving average** answers “how much are we selling per day, lately?” It adds up the last seven days and divides by seven. Retail and web teams love it because it irons out the weekday/weekend rhythm.

The window comes from `DATESINPERIOD` with the `DAY` interval: `DATESINPERIOD('Date'[Date], MAX('Date'[Date]), -7, DAY)` is the last visible day and the six before it.

Now the divisor. In the previous recipe, months before the data began were **missing**, so we only averaged the months we had. A day with no sales inside the window is different: the shop was open and sold nothing. That is a real **zero**, so it must count. Averaging only the days with sales (which is what `AVERAGEX` over dates does, since it skips blanks) inflates the number.

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

Units per Day (Last 30) = DIVIDE(CALCULATE([Total Quantity], DATESINPERIOD('Date'[Date], MAX('Date'[Date]), -30, DAY)), 30)