Forum Discussion
SuddenClarity
3 years agoHelper I
SAMEPERIODLASTYEAR doesn't work as a variable
I tried to write the following: Sales YoY = VAR CY = [Total Sales] VAR PY = CALCULATE(CY, SAMEPERIODLASTYEAR('Calendar'[Date])) RETURN IF ( ISBLANK (PY), BLANK(), CY - PY ) But it r...
- 3 years ago
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.
FreemanZ
3 years agoSuper 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.