Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
Hi,
I'm trying to understand, how the first argument of the SWITCH-function is being evaluated/calculated when checking the second arguments.
Here an example:
SWITCH (
SELECTEDVALUE( Product[Color] ) ,
"Green", 1,
"Blue", 2,
"Red", 3
)
Will the SELECTEDVALUE ( Product[Color] ) be calculated at the beginning, then saved like a variable, and then in the second step only compared to the different colors? Or is it computed for every line of comparison new?
Personally I think that it is beeing calculated once, stored, and then compared. But I was wondering, because I saw someone writing the SWITCH-Function with a variable as TRUE/FALSE argument:
var color = SELECTEDVALUE( Product[Color] )
RETURN
SWITCH (
color ,
"Green", 1,
"Blue", 2,
"Red", 3
)
And this got me thinking, maybe I was wrong. Would be great if someone could enlighten me 😉
PS: I'm just curious if there is a difference in performance, that there could be differences when the function is being evaluated row by row I'm aware 🙂
Regards,
Max
Solved! Go to Solution.
hi @Anonymous
SWITCH is runned as nested IFs. So the performance shall be better to save the first argument as a variable. As a variable is calculated once, while without varible, it is calculated in every nested IF, three times in your case.
hi @Anonymous
SWITCH is runned as nested IFs. So the performance shall be better to save the first argument as a variable. As a variable is calculated once, while without varible, it is calculated in every nested IF, three times in your case.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
16 | |
13 | |
12 | |
11 | |
11 |
User | Count |
---|---|
19 | |
14 | |
14 | |
11 | |
9 |