Forum Discussion
Anonymous
2 years agoNot applicable
Why using the VARiable changes the result
Can someone please explain to me the expected difference in these two DAX measures. One contains a variable (VAR) "SpendSum" and the other does not. Needless to say I was getting different results ...
Anonymous
2 years agoNot applicable
In Measure 1, SUMX is inside CALCULATE, so it's evaluated under the filter context created by CALCULATE. The context is the specific month set by DATESBETWEEN.
In Measure 2, SUMX is calculated outside of CALCULATE (in the variable SpendSum), so it sums over the entire table without the month-specific filter context. Then, CALCULATE doesn't affect the value of SpendSum since it's already computed. It's like having a constant value.
- Anonymous2 years agoNot applicable
Thanks, for the explanation. In this case, the formula was small enough that the VAR wasn't necessary. So, if I have a filter to apply, I may need to include that in the VAR instead of in the main body of the measure. I cannot just simply consider my VAR to be an exact substitute for all contexts.