When Things Get Weird with Custom Calendars in Tabular Models
Summary
This article investigates unexpected behaviors and challenges within Power BI's new calendar-based time intelligence feature, specifically concerning custom calendars and the DAX "DATEADD()" function. It reveals that "DATEADD()" with `YEAR` granularity can cause a 1-day shift in previous year (PY) values when comparing leap years to non-leap years, a problem solvable by using "DATEADD()" with `-12, MONTH` granularity or a custom calendar with uniform month lengths. The author also notes inconsistent weekly PY calculation results, sometimes requiring a data model rebuild, and difficulties in mixing weekly and monthly logic due to calendar category alignment issues. Despite these complexities, weekly calculations correctly map PY values based on week and weekday, demonstrating reliable behavior when periods are of consistent length. The feature, still in preview, presents both powerful capabilities and significant implementation nuances for Power BI developers.
Key takeaway
Power BI's new calendar-based time intelligence introduces critical `DATEADD()` pitfalls for custom calendars, especially with unequal period lengths like leap years. Daily Previous Year (PY) calculations using `DATEADD(..., -1, YEAR)` can shift by one day; use `DATEADD(..., -12, MONTH)` as a robust workaround, but be aware of unexplained inconsistencies in weekly PY calculations. Data modelers must carefully manage these behaviors and the challenges of mixing calendar types to ensure accurate time intelligence.
Topics
- Custom Calendars
- DAX Time Intelligence
- DATEADD Function
- Power BI Tabular Models
- Leap Year Calculations
Code references
Best for: Data Analyst, Analytics Engineer, Consultant
Related on AIssential
Editorial summary, takeaway, and curation by AIssential. Original article published by Towards Data Science.