Forum Discussion
julien-rivley
6 years agoHelper I
Performance and IF statement
Hi, I have a surprising performance issue in DAX. I have a slow measure that I use to calculate future expiry of product per month(based on current stock by expiry month and sales forecast). T...
- 6 years agoHi julien-rivley ,Because measures are calculated on the fly, the [test measure] expression is calculated twice. [test measure] is first calculated for the condition check and then for the true condition expression.
Instead of calculating the same expression multiple times, you can store the resulting measure value in a variable. You can use a variable reference wherever required.optimized measure =
var test_measure = [test measure]
return IF(test_measure=0,0,[slow measure])For more details, please refer to this document:https://www.sqlbi.com/articles/optimizing-if-conditions-using-variables/Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
V-lianl-msft
6 years agoCommunity Support
Hi julien-rivley ,
Because measures are calculated on the fly, the [test measure] expression is calculated twice. [test measure] is first calculated for the condition check and then for the true condition expression.
Instead of calculating the same expression multiple times, you can store the resulting measure value in a variable. You can use a variable reference wherever required.
Instead of calculating the same expression multiple times, you can store the resulting measure value in a variable. You can use a variable reference wherever required.
optimized measure =
var test_measure = [test measure]
return IF(test_measure=0,0,[slow measure])
var test_measure = [test measure]
return IF(test_measure=0,0,[slow measure])
For more details, please refer to this document:https://www.sqlbi.com/articles/optimizing-if-conditions-using-variables/
Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.