Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
Hi everybody,
I am running into the following issue. I am conviced it is related to me not propberly understanding (yet) how variables are being calculated, so any explenation would be greatly appreciated...
This is my DAX measure (it does not make sense by itself, I just slimmed it down to the essence of my issue). YearMonth is a field from a properly developed Calendar Table
Solved! Go to Solution.
Hi @JuanSombrero ,
Variables can be used anywhere but are evaluated in the context in which they are written.
You can refer the below blog for more understanding
https://radacad.com/caution-when-using-variables-in-dax-and-power-bi
Regards,
Harsh Nathani
Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)
The variable is calculated once per context.
For example:
Distance from Average=
VAR _Avg = AVERAGE(Sales[Sales])
RETURN
AVERAGEX(
VALUES(Users[Id]),
SUM(Sales[Sales])-_Avg
)
Would return the average difference from the average of ALL selected users (rather than each individual user's average), unless the row context is the specific user.
Hi @JuanSombrero ,
Create this as a separate measure.
Sales Measure = SUM('Invoice detail'[Total excl. VAT])
and then try
VAR Sales_LM = CALCULATE([Sales Measure], DATEADD('Calendar'[Date],-1,MONTH))
Regards,
Harsh Nathani
Hi Harsh,
that would indeed solve the issue. But could you explain me as well why my solution is not working? I have a feeling that the 'why' is very important here for me not to run into comparable issues in the future.
Thx
Jan
Hi @JuanSombrero ,
Variables can be used anywhere but are evaluated in the context in which they are written.
You can refer the below blog for more understanding
https://radacad.com/caution-when-using-variables-in-dax-and-power-bi
Regards,
Harsh Nathani
Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)