DAX SAMEPERIODLASTYEAR function
Returns the dates in view, shifted back one year.
SAMEPERIODLASTYEAR is the standard way to compare with last year. Used as a filter in CALCULATE, it moves whatever period is in view (a month, a quarter, a year) back twelve months.
Syntax
SAMEPERIODLASTYEAR(<dates>)| Argument | Required | Description |
|---|---|---|
| dates | Required | The date column of your date table. |
Returns: A table of dates, used as a filter.
Examples
Calculated on the free practice data (table financials), with [Total Sales] = SUM(financials[Sales]) and [Total Profit] = SUM(financials[Profit]).
1. Sales last year, by year
Sales LY = CALCULATE([Total Sales], SAMEPERIODLASTYEAR(Dates[Date]))| Year | Sales LY |
|---|---|
| 2013 | (blank) |
| 2014 | 26,415,255.51 |
2013 has no previous year, so it is blank. 2014 shows 2013's sales, which cover only September to December.
Good to know
- Comparing a full year with a partial one is misleading: check the date range before showing growth.
- DATEADD(Dates[Date], -1, YEAR) does the same and can shift by any number of periods.
Related functions
Official reference: SAMEPERIODLASTYEAR function on Microsoft Learn