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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

Slow Switch Statement

Hey,

 

I'm trying to create one measure, that will return other measures based on another unrelated 'Measure' table, that I will use as a column in a Matrix. The below DAX expression does the trick, but its SO slow. I think its calculating every measure, rather than just the selected few. Anyone got any ideas around this at all? I've tried using IF(), and i've tried using SWITCH(TRUE(),"Actual",[Actual]........). I can't find a way around it, but it's a real necessity for the users to be able to filter between the different measures as they need

 

MasterP&LMeasure =
VAR SelectedMeasure = SELECTEDVALUE('Measure Select'[Measure Select])
RETURN

SWITCH(SelectedMeasure,
"Actual",[Actual],
"Forecast",[Forecast],
"Budget",[Budget],
"Client Budget",[Client Budget],
"Prior Year",[Prior Year],
"Actual vs Forecast",[Actual vs Forecast],
"Actual vs Budget",[Actual vs Budget],
"Actual vs Client Budget",[Actual vs Client Budget],
"Actual vs Prior Year",[Actual vs Prior Year],
"Forecast vs Budget",[Forecast vs Budget],
"Forecast vs Client",[Forecast vs Client Budget],
"Forecast vs Prior Year",[Forecast vs Prior Year],
"Actual All Years",[Actual All Years],
"Forecast All Years",[Forecast All Years],
"Budget All Years",[Budget All Years],
"Client Budget All Years",[Client Budget All Years],
"Actual vs Forecast All Years",[Actual vs Forecast All Years],
"Actual vs Budget All Years",[Actual vs Budget All Years],
"Actual vs Client Budget All Years",[Actual vs Client Budget All Years],
"Forecast vs Budget All Years",[Forecast vs Budget All Years],
"Forecast vs Client Budget All Years",[Forecast vs Client Budget All Years]
)
8 REPLIES 8

 

Financials Example BI.png

 

I had an issue with something similiar and was able to get away with this via structure formatting of the visuals. If you were to split the variances into separate visuals next to each other you'd experience much better performance I'd imagine. I attached a screenshot of my example with very long switch statements with complex modeling in the underlying measures used in the swith. This entire page takes ~10 seconds to load.

 

So something like:

 

  • Forecast Variances
  • Budget Variances
  • All Year Variances

 

Or you can elect to section based on

 

  • Variances vs versions
  • Variances vs time

 

Either way, I think you can improve performance via thinking about your formatting.

v-xicai
Community Support
Community Support

Hi @Anonymous ,

 

Az38' suggestion is great.  In addition, you may improve the performance of measures used in your SWITCH formula, such as [Actual], [Forecast], [Budget],,,etc. 

 

For example:

 

Use SELECTEDVALUE() instead of VALUES()

 

Use ISBLANK() instead of =Blank() check

 

Do not use scalar variables in SUMMARIZE()

 

Use variables instead of repeating measures inside the IF branch

 

You may refer to the tips:

 

Improve Power BI Performance by Optimizing DAX

 

A comprehensive guide to Power BI performance tuning

 

Best Regards,

Amy 

 

Community Support Team _ Amy

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Thanks for the feedback. Unfortunately I've already optimised the source measures and don't think I can speed them up much more. The real issue is with the consolidation of the measures in the switch

az38
Community Champion
Community Champion

Hi @Anonymous 

try step 2 and step 3 in this https://community.powerbi.com/t5/Community-Blog/Performance-Tuning-DAX-Part-1/ba-p/976275 workaround by @Greg_Deckler 


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
Anonymous
Not applicable

Thanks for your reply! I've spent a good while trying to apply this to my Dax and can't figure it out. Step 2 relies on the number of entries in a table but mine is an unlinked table with one instance of each in the table. Step 3 I don't really see how I can apply it either. If you can give any guidance on how I could specifically apply them to my situation id really appreciate any help

parry2k
Super User
Super User

@Anonymous do you know if this is the switch is slow or the measures used in switch are slow, what happens if you use these measures directly, and see if these measures are not performing as expected.

 

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

The measures are taking just short of 5 seconds each to load per performance analyser. If I have 4 measures filtered in the measure table, i was expecting about 20 seconds max for the table. Instead its taking 80/90 seconds to load this single switch measure, with no other visuals or measures on the page. Googling it, it seems that switch does perform this way, and calculates every measure regardless of its use - just wondering if anyone had any ideas at all on alternative solutions

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.