Forum Discussion
Sameperiodlastyear function is not working - returns current year's data
- 8 years ago
Hi sirgseymour,
Sameperiodlastyear() will return a table that contains a column of dates shifted one year back in time from the dates in the specified dates column, in the current context. So the fucntion is based on current context which should not be used in your senario.
As a workaround, create a measure using DAX like this pattern and check if it can meet your requirement:
Result = VAR Previous_Year = DATE(YEAR(MAX(Table1[Date])) - 1, MONTH(MAX(Table1[Date])), DAY(MAX(Table1[Date]))) RETURN CALCULATE(MAX(Table1[Sales]), FILTER(ALL(Table1), Table1[Date] = Previous_Year))
Regards,
Jimmy Tao
Hi sirgseymour,
Sameperiodlastyear() will return a table that contains a column of dates shifted one year back in time from the dates in the specified dates column, in the current context. So the fucntion is based on current context which should not be used in your senario.
As a workaround, create a measure using DAX like this pattern and check if it can meet your requirement:
Result = VAR Previous_Year = DATE(YEAR(MAX(Table1[Date])) - 1, MONTH(MAX(Table1[Date])), DAY(MAX(Table1[Date]))) RETURN CALCULATE(MAX(Table1[Sales]), FILTER(ALL(Table1), Table1[Date] = Previous_Year))
Regards,
Jimmy Tao
This solution seems to be showing a different number than the previous year's value..