PREVIOUSMONTH vs DATEADD in DAX: Why They Disagree on the 31st
Both look like 'last month' but return different date sets on the 31st. When each is correct, and how to check which one your model needs.
Date-based calculations and YTD/MTD patterns.
7 tutorials in this category
Year-to-date, month-over-month, rolling twelve weeks — this is most of what business reporting actually asks for, and it is also where DAX fails most quietly. The functions are short. The reason they return the wrong number is almost never the function itself: it is the date table underneath.
Read the calendar table setup before anything else. A marked date table that is contiguous, starts before your earliest fact and ends after your latest one, and is related to every fact table is the precondition for all of it. After that, the YTD/QTD/MTD pattern and the year-over-year comparisons cover the bulk of real requests, with rolling averages as the generalisation once windows stop being calendar-aligned.
Power BI's automatic date/time is the usual culprit in a model that produces plausible but wrong time intelligence. It creates hidden tables that work well enough to hide the problem until you add a second fact table or a fiscal calendar, at which point the numbers drift and nothing in the measure looks wrong.
Both look like 'last month' but return different date sets on the 31st. When each is correct, and how to check which one your model needs.
A date table is the backbone of any Power BI model that needs time intelligence.
Stop rewriting time comparisons. Use this copy-paste DAX template for MoM, YoY, MoM %, and YoY % that works with any marked Date table.
TOTALYTD, DATEADD and SAMEPERIODLASTYEAR only work with a proper calendar table. The setup, the syntax, and five errors that break YTD.
YoY, MoM and QoQ with SAMEPERIODLASTYEAR and DATEADD, plus the comparison patterns for fiscal years and non-standard periods.
A 7-day rolling average, a 30-day moving sum, and the DAX window functions that generalise to any window you need.
Calendar table setup, YTD/QTD/MTD, year-over-year and rolling averages: the four patterns that cover most business reporting.