DAX Last 7, 30, and 90 Days Sales Measure

Sums sales over a fixed trailing window of days from the last date with data, ignoring any date filter already applied.

Time IntelligenceIntermediatetime intelligencetrailing dayslast n days

DAX code

Last 7 Days Sales =
VAR LastDate = MAX('Date'[Date])
RETURN
    CALCULATE([Total Sales], DATESINPERIOD('Date'[Date], LastDate, -7, DAY), ALL('Date'))

Last 30 Days Sales =
VAR LastDate = MAX('Date'[Date])
RETURN
    CALCULATE([Total Sales], DATESINPERIOD('Date'[Date], LastDate, -30, DAY), ALL('Date'))

Last 90 Days Sales =
VAR LastDate = MAX('Date'[Date])
RETURN
    CALCULATE([Total Sales], DATESINPERIOD('Date'[Date], LastDate, -90, DAY), ALL('Date'))

Generate a Power BI date table

Notes

ALL('Date') ignores whatever date filter is active so the window is always relative to today's last loaded date; drop it if you want the window relative to the current filter instead.

Requirements

Builds on these measures

How to use this measure

  1. In Power BI Desktop, select the table that should hold the measure and choose New measure on the ribbon.
  2. Paste the code, then replace the placeholder table and column names with your own. The My table names fields above do this for you.
  3. Run it through the DAX Formatter if you want it laid out in your team's style.

Related DAX measures

More DAX resources

Browse all 175 measures in the Power BI DAX Measures Library, or search the library for something similar to Last 7, 30, and 90 Days Sales.