Forum Discussion
Seeking clarity on optimization re: Variables, Switch Statements
Let's say there is a single-select slicer with the following options from a column, 'Selection_Options'[Options]:
"Inbound"
"Outbound"
"Total"
In an accompanying line graph visual, depending on the slicer selection, a measure with a switch statement will be used to display a different measure.
Here is the accompanying measure used in the visual.
- Anonymous2 years ago
Hi kpost ,
In DAX, variables () are evaluated once at the point they are defined in the formula. This means that all variables in your second are calculated regardless of the statement's outcome.
Given this, your assumption is correct. The first approach, where the measures and are calculated directly within the statement based on the slicer selection, is more efficient. This is because, in this scenario, only the measure corresponding to the selected option is calculated.
Hope it helps!
Best regards,
Community Support Team_ Scott ChangIf this post helps then please consider Accept it as the solution to help the other members find it more quickly.
1 Reply
- AnonymousNot applicable
Hi kpost ,
In DAX, variables () are evaluated once at the point they are defined in the formula. This means that all variables in your second are calculated regardless of the statement's outcome.
Given this, your assumption is correct. The first approach, where the measures and are calculated directly within the statement based on the slicer selection, is more efficient. This is because, in this scenario, only the measure corresponding to the selected option is calculated.
Hope it helps!
Best regards,
Community Support Team_ Scott ChangIf this post helps then please consider Accept it as the solution to help the other members find it more quickly.