Forum Discussion
SAMEPERIODLASTYEAR doesn't work as a variable
I tried to write the following:
the issue is from the nature of variable in DAX. Once defined, a variable is stored as a constant. So whatever filter you add in expressions like
CALCULATE(CY, SAMEPERIODLASTYEAR('Calendar'[Date]))
it simply return CY, a constant defined before.
So CALCULATE([Total Sales], SAMEPERIODLASTYEAR('Calendar'[Date])) is the right approach.
2 Replies
- FreemanZSuper User
the issue is from the nature of variable in DAX. Once defined, a variable is stored as a constant. So whatever filter you add in expressions like
CALCULATE(CY, SAMEPERIODLASTYEAR('Calendar'[Date]))
it simply return CY, a constant defined before.
So CALCULATE([Total Sales], SAMEPERIODLASTYEAR('Calendar'[Date])) is the right approach.
- Clinical_EpiAdvocate III
Dear Sudden Clarity,
You could use same period last year as a Variable - see my example where as Variable is using same periodlastyear
Test measure =VAR TY = TOTALYTD(COUNT('IP SQL Data'[URN]),_Date[Date filter])VAR LY = CALCULATE(COUNT('IP SQL Data'[URN]),SAMEPERIODLASTYEAR(_Date[Date filter]))RETURN TY / LYHope this confirms with you it can be done 🙂and with date change,
Kind regards,Clin Epi