The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
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
Solved! Go to Solution.
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.
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!
Proud to be a Super User!
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.
User | Count |
---|---|
16 | |
8 | |
7 | |
6 | |
6 |
User | Count |
---|---|
26 | |
13 | |
12 | |
8 | |
8 |