How to calculate rolling 12 months in DAX: step by step
Learn how to create a rolling 12 months measure in DAX to sum sales for the last 12 rolling months — an essential technique to analyze trend, compare year-over-year performance and smooth seasonality (e.g. peaks in December). This tutorial explains why the approach works, shows step by step how to implement it using a Calendar/Date table and includes concrete examples and practical checks to ensure reliable results.
Prerequisites
- Model in Power BI or Analysis Services with a fact table (e.g.: Sales) and a date table (e.g.: Calendar/Date).
- Relationship between Sales[Date] and Calendar[Date] (type 1:* and proper filter direction).
- Numeric sales column in Sales (e.g.: Sales[Revenue]) formatted as currency or decimal.
- Calendar/Date table marked as Date table in Power BI to ensure Time Intelligence functions work correctly.
Without these elements, time-based measures can return incorrect results: for example, if a month is missing in the Calendar, a rolling 12 will skip that month and reduce the sum. Also check that date columns are of type Date and not text.
Step 1: Why use rolling 12 months in DAX
A 12-month moving sum (rolling 12) shows the accumulated evolution of the last 12 months up to each date. This reduces noise from monthly fluctuations and is useful to identify real trends: for example, if a product has monthly sales between 80,000 and 150,000, the Rolling 12M value smooths these variations and allows comparing equivalent periods with less volatility.
Another practical benefit: by comparing the Rolling 12M measure today with the same metric 12 months earlier you can see continuous growth (e.g. +12% YoY) without being misled by seasonal spikes in a single month.
Step 2: Create a Calendar/Date table (if you don’t have one)
You need a continuous date table — for example from 2018-01-01 to 2026-12-31. The table should include Year, Month and a YearMonth key for axes. After creating it, mark it as Date table in Power BI and connect it to Sales.
Calendar =
ADDCOLUMNS(
CALENDAR(DATE(2018,1,1), DATE(2026,12,31)),
"Year", YEAR([Date]),
"Month", MONTH([Date]),
"YearMonth", FORMAT([Date], \"YYYYMM\")
)
Practical example: a continuous Calendar ensures that DATESINPERIOD or DATESBETWEEN will consider all days — if 1 month is missing the accumulations will be incorrect.
Step 3: Basic Sales measure
First create the simple measure that sums revenue. This measure is the basis for all rolling variations.
Total Revenue = SUM(Sales[Revenue])
If sales are the result of Quantity * UnitPrice, prefer SUMX(Sales, Sales[Quantity]*Sales[UnitPrice]). Use DIVIDE when calculating ratios to avoid division by zero.
Step 4: Rolling 12 months measure (12M)
This measure uses DATESINPERIOD with the Calendar[Date] column to collect the last 12 months up to the date in the current filter context. It works in visuals with daily, monthly or yearly granularity.
Rolling 12M Revenue =
VAR LastDate = MAX(Calendar[Date])
VAR DateRange = DATESINPERIOD(Calendar[Date], LastDate, -12, MONTH)
RETURN
CALCULATE(
[Total Revenue],
DateRange
)
Example: if the context has LastDate = 2026-06-30, DateRange will typically correspond to 2025-07-01 through 2026-06-30 (all dates of those 12 months). This means that, at the 2026-06 point, the measure shows the sum of sales for those 12 months.
Step 5: Robust alternative with PARALLELPERIOD and handling missing dates
If there are gaps in the fact table or year-level filters, prefer using ALL(Calendar) inside DATESBETWEEN to prevent the local context from trimming the interval. Also check if LastDate is BLANK to avoid errors in visuals without a selected date.
Rolling 12M Revenue (robust) =
VAR LastDate = MAX(Calendar[Date])
RETURN
IF(
ISBLANK(LastDate),
BLANK(),
CALCULATE(
[Total Revenue],
DATESBETWEEN(
ALL(Calendar[Date]),
EDATE(LastDate, -11),
LastDate
)
)
)
If you prefer to require 12 complete months (e.g. avoid partial values in the first 11 months), add a check for months present:
// require 12 complete months
VAR DateRange = DATESINPERIOD(Calendar[Date], LastDate, -12, MONTH)
VAR MonthsPresent = COUNTROWS(SUMMARIZE(DateRange, Calendar[Year], Calendar[Month]))
IF(MonthsPresent < 12, BLANK(), CALCULATE([Total Revenue], DateRange))
Step 6: Example of use in visuals (month by month)
To show the month-by-month series, use Calendar[YearMonth] or the Year/Month hierarchy on the axis and display the Rolling 12M Revenue measure. Set the axis to continuous (type: continuous) to avoid gaps between months and ensure the axis formatting shows a single point per month.
// In Power BI choose:
// Axis = Calendar[Date] (type continuous) or Calendar[YearMonth]
// Values = [Rolling 12M Revenue]
Practical tip: when comparing two products, place the same measure on separate lines and use the same Y-axis scale to easily compare trends (e.g. 0–2M euros).
Verify the result
Check that for each point the sum corresponds to the previous 12 months. Useful and concrete tests:
- Choose LastDate=2021-12-31 and compare Rolling 12M with a manual sum filtered between 2021-01-01 and 2021-12-31; the values should match.
- In the first 11 months of the calendar, confirm the behavior: if you opt to require 12 complete months you will see BLANK; otherwise you will see the partial sum for those months.
- If you notice unexpected drops, check if there are months without sales in the Sales table or if the relationship with Calendar is correct.
Conclusion
You now have a rolling 12 months measure in DAX ready to analyze sales trends with less noise. Next practical steps: create variations such as a 3-month moving average, normalize by number of business days or add YoY comparisons. Whenever a discrepancy arises, first confirm the integrity of the Calendar/Date table and the model relationships.