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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
worthywow1988
Frequent Visitor

Slow Switch Performance

Hi!

 

I have a switch statement to select a measure depending on the level the user wants to view. The code is similar to this:

 

Selected View = switch(TABLE_VIEW [Selected View],0,[Measure0],1,[Measure1],2,[Measure2],3,[Measure3],4,[Measure4],5,[Measure5])

 

 

It was running slowly (~10 seconds) so I did some experimenting. If I do the following it runs relatively quickly (~1.5 seconds)

 

Selected View = [Measure1]
Selected View = switch(TABLE_VIEW [Selected View],1,[Measure1])

 

 

The speed was roughly pro rata with the number of switch conditions so it seems to be the case that all the options in SWITCH are calculated regardless of if the test is true or false - is this as expected?

 

Is there any logic/code I can use so it only ends up calculating the selected/required measure?

 

Thanks!

 

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @worthywow1988 

 

You can put the measures into separate card visuals and use Performance Analyzer to test the run time. The run time is divided into three parts, of which the DAX query is mainly related to the calculation of the formula. You can check which part is causing the difference in running time.

Use Performance Analyzer to examine report element performance in Power BI Desktop - Power BI | Micr...

vjingzhanmsft_0-1739257462043.png

 

Best Regards,
Jing

View solution in original post

3 REPLIES 3
worthywow1988
Frequent Visitor

Hi Greg - thanks for your reply. I thought that would be the behaviour but it seems to be doing something different i.e. if [Selected View] is, say 1, then

 

Selected View = switch(TABLE_VIEW [Selected View],1,[Measure1],2,[Measure2],3,[Measure3],4,[Measure4],5,[Measure5])

 

takes much longer to run then the below

 

Selected View = switch(TABLE_VIEW [Selected View],1,[Measure1])

 

when it theory it should take the same time?!

Anonymous
Not applicable

Hi @worthywow1988 

 

You can put the measures into separate card visuals and use Performance Analyzer to test the run time. The run time is divided into three parts, of which the DAX query is mainly related to the calculation of the formula. You can check which part is causing the difference in running time.

Use Performance Analyzer to examine report element performance in Power BI Desktop - Power BI | Micr...

vjingzhanmsft_0-1739257462043.png

 

Best Regards,
Jing

Greg_Deckler
Community Champion
Community Champion

@worthywow1988 Put your most frequent values first. The SWITCH stops evaluating once a condition evaluates to TRUE. So, for example, let's say that 50% of your cases are 5, you would want that to be the first evaulation condition. Then if your next highest is 3, then that should be the second, and so on.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.

Top Solution Authors