The SAMEPERIODLASTYEAR function returns a table containing a column of dates that match those involved in the current context, shifted back one year.
SAMEPERIODLASTYEAR(
dates
)
- dates: Column containing dates.
The SAMEPERIODLASTYEAR function returns a table.
The dates argument can be a reference to a column containing dates, an expression that returns a table with a single column containing dates, or a Boolean expression that defines a table with a single column containing dates.
The result returned by this function is the same as that returned by the DATEADD function, specifying as a period to add a year back in time:
DATEADD (dates, -1, YEAR)
If, in a table containing sales information, we define the measure:
Ventas = SUM(FactSales[SalesAmount])
...calculating the sum of sales in the period involved in the context, we can show the sales by year and month in a matrix type visualization:
We can then create a measure to calculate sales for the same period as the one involved in the context a year earlier:
Ventas año anterior = CALCULATE([Ventas], SAMEPERIODLASTYEAR(DimDate[Datekey]))
If we take this measure to the previous matrix, we obtain the following:
It can be seen how, indeed, this last measure returns the sum of sales for the previous year.