Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Performance of SWITCH()

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

1 ACCEPTED SOLUTION
FreemanZ
Super User
Super User

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.

View solution in original post

1 REPLY 1
FreemanZ
Super User
Super User

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.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.