Forum Discussion
VAR Statement and Time Intelligence
Hello,
I have an issue with using time intelligence function and VARIABLES.
Below code works fine:
PY Volume =
CALCULATE ( [BlendedQty], SAMEPERIODLASTYEAR ( DIM_CALENDAR[Date] ) )
However, below code which basically is the same thing but using VAR statements. What am I doing wrong? Thanks
PY VolumeTEST =
VAR Qty = [BlendedQty]
VAR PreviousQTY = CALCULATE(Qty,SAMEPERIODLASTYEAR(DIM_CALENDAR[Date]))
RETURN
PreviousQTY
Hello daxreport
When calculated as a variable first it is in the evaluation context of the visual. Putting the variable inside the CALCULATE(variable, SAMEPERIODLASTYEAR(... does not recalculate the expression in the desired new evaluation context.
2 Replies
- some_bihCommunity Champion
Hi daxreport variables in DAX are simply lazy evaluation processed, meaning once calculated it is fixed value / amount. So when you want to reuse it in CALCULATE for context transition, this is what CALCULATE DO, then results could be unexpected (your second measure with VAR).
Did I answer your question? Mark my post as a solution! Kudos Appreciated!