Forum Discussion
When does a variable gets calculated? Before or after RETURN?
In DAX, variables declared within a measure are evaluated only when they are referenced, and not when they are declared. This means that DAX will not calculate all the variables (a, b, c, d) in advance before the SWITCH function. Instead, the evaluation will happen conditionally, based on the logic inside the SWITCH function.
In your case, the SWITCH function will be evaluated first to determine which condition is TRUE(). Once a matching condition is found, only the corresponding variable (a, b, c, or d) will be calculated.
For example:
- If condition 2 is TRUE(), then only var b will be calculated, and the rest (a, c, d) will be ignored.
- If none of the conditions are met, none of the variables will be calculated.
Thus, for performance, this approach is efficient because the complex calculations will only be executed when needed, based on the result of the SWITCH function. So, it won't affect performance negatively as long as your conditions are properly defined.
Did I answer your question? Mark my post as a solution! Appreciate your Kudos !!
Let's Connect on LinkedIn: https://www.linkedin.com/in/anmol-malviya/?originalSubdomain=in