The SAMEPERIODLASTYEAR function is a DAX time intelligence function used to compare values for the same period in the previous year. It is commonly used to analyze trends and year-over-year (YoY) performance.
This function works only with a Date Table that is marked as a Date Table in Power BI.
Syntax
SAMEPERIODLASTYEAR(<dates>)
- dates โ A column from your Date Table containing the dates to shift back one year.
Example 1 โ Basic Year-over-Year Sales
Sales LY = CALCULATE(
SUM(Sales[Amount]),
SAMEPERIODLASTYEAR(DateTable[Date])
)
- This measure calculates total sales for the same period in the previous year.
- If you filter the report to March 2024, the measure will return total sales for March 2023.
Example 2 โ Comparing YTD with Previous Year
Sales YTD LY = CALCULATE(
TOTALYTD(SUM(Sales[Amount]), DateTable[Date]),
SAMEPERIODLASTYEAR(DateTable[Date])
)
- This measure calculates Year-to-Date sales for the previous year.
- Useful for comparing cumulative performance over time.
How It Works
- SAMEPERIODLASTYEAR shifts the filter context back by one year.
- It respects the existing filters in visuals or slicers.
- Works with measures rather than calculated columns because it depends on filter context.
Best Practices
- Always use a dedicated Date Table with continuous dates.
- Mark the Date Table as a Date Table to enable correct time intelligence calculations.
- Combine SAMEPERIODLASTYEAR with CALCULATE to perform meaningful aggregations.
- Use in combination with visuals like line charts to highlight year-over-year trends.
Conclusion
SAMEPERIODLASTYEAR is an essential DAX function for year-over-year analysis in Power BI. It allows you to compare performance dynamically across periods, helping to identify trends and monitor business growth over time.