Vorjahresvergleiche auf Tagesebene mit DAX im Falle von Schaltjahren
3 min read
2 months ago
Published on Jun 09, 2025
This response is partially generated with the help of AI. It may contain inaccuracies.
Table of Contents
Introduction
In this tutorial, we'll explore how to perform year-over-year comparisons on a daily basis using DAX, particularly focusing on leap years. Leap years introduce unique challenges, especially when analyzing data that includes February 29. This guide will provide you with actionable steps to handle these scenarios effectively in your reports.
Step 1: Understanding Leap Years and Their Impact
- Leap years occur every four years, adding an extra day, February 29.
- This additional day can skew year-over-year comparisons if not accounted for, especially in reporting tools like Power BI.
- Recognize that any analysis must include logic to handle or exclude February 29, depending on the data context.
Step 2: Preparing Your Dataset
- Ensure your dataset includes a date field that contains all the necessary dates, including February 29 for leap years.
- Make sure you have a date table that is marked as a date table in your Power BI model. This is crucial for DAX time intelligence functions to work correctly.
- Example of creating a date table in DAX:
DateTable =
ADDCOLUMNS(
CALENDAR(MIN(Sales[OrderDate]), MAX(Sales[OrderDate])),
"Year", YEAR([Date]),
"Month", MONTH([Date]),
"Day", DAY([Date]),
"IsLeapYear", IF(MOD(YEAR([Date]), 4) = 0 && (MOD(YEAR([Date]), 100) <> 0 || MOD(YEAR([Date]), 400) = 0), TRUE, FALSE)
)
Step 3: Writing DAX Measures for Year-Over-Year Comparisons
- Create a measure to calculate sales for the current year, ensuring it excludes February 29 when not in a leap year.
- Example DAX measure for total sales:
TotalSales = SUM(Sales[SalesAmount])
- Create another measure to calculate last year's sales, incorporating logic to handle leap years:
LastYearSales =
CALCULATE(
[TotalSales],
SAMEPERIODLASTYEAR(DateTable[Date]),
NOT(DateTable[IsLeapYear]) || (DateTable[Day] <> 29)
)
Step 4: Visualizing the Data
- Use Power BI visuals like line charts or bar charts to display year-over-year comparisons.
- Ensure your visuals are set to filter out February 29 for non-leap years.
- Validate your reports by comparing totals for leap and non-leap years to ensure your DAX measures are functioning as expected.
Step 5: Testing and Validating Your Results
- After implementing your DAX measures, test them against known data points.
- Create a report that includes both leap year and non-leap year data to visually confirm the accuracy of your comparisons.
- Adjust your DAX logic if any discrepancies are found.
Conclusion
Handling year-over-year comparisons in the presence of leap years requires careful consideration of date logic in DAX. By following these steps, you can ensure your reports remain accurate and informative. For further learning, consider exploring more advanced DAX functions and Power BI features, or refer to the provided resources for additional training and tools.