Understanding the optimization of SWITCH

Поділитися
Вставка
  • Опубліковано 25 вер 2024
  • The SWITCH function in DAX has been optimized over the years, and it is helpful to know what makes the optimization work best.
     
    Article and download: sql.bi/754856?...
    How to learn DAX: www.sqlbi.com/...
    The definitive guide to DAX: www.sqlbi.com/...

КОМЕНТАРІ • 18

  • @stevecoleman9522
    @stevecoleman9522 2 роки тому +3

    This video and associated article are very enlightening Marco. Thank you.
    The Formula Engine behavior can be a mystery, but videos like this shed light on how the FE works.

  • @azajoey1
    @azajoey1 2 роки тому +4

    I actually used index / id based switch in my recent project. as the model grew, one visual started to run for 30 seconds. I thought integer based switch will be a good solution. then i tried using the same descriptive column which is present in the slicer and become 3 seconds, and ever since then with further logic and complexity added, remained with same performance. obviously my choice was simply a brute force try-catch, but still! amazing! thanks for the deep-dive

  • @louism.4980
    @louism.4980 4 місяці тому +1

    Very technical, thank you for sharing your knowledge! :)

  • @johansantacruz6464
    @johansantacruz6464 2 роки тому +3

    Thanks for this video! It's clear and useful for DAX devs.

  • @craniumnr
    @craniumnr Рік тому +1

    Nice video, but I have some questions in my mind:
    1- What if we are using live connection?
    2- What if we have filters on the visual we have the measure and not on the slicer?
    3- What if we have more than 1 slicer?
    4- What if we have filters within the measures?

  • @Bharath_PBI
    @Bharath_PBI 2 роки тому +2

    Thank you master, feel like watching your video after a long time.

  • @MuscleMUSEums
    @MuscleMUSEums 2 місяці тому +1

    thank you very much, amazingly explained!

  • @michaelmuell
    @michaelmuell Рік тому +1

    Thanks so much for this! ❤
    A dashboard suddenly had incredibly long (>30 sec) load times after I made the pages dynamic using SWITCH. I couldn't figure out why.
    In the end, removing a page filter solved the problem and decreased the load time to 2 sec.

  • @fly2sky99
    @fly2sky99 2 роки тому +1

    Thanks for great video. Interesting to know what's happending inside the engine.

  • @noahhadro8213
    @noahhadro8213 Рік тому

    I have a measure that looks like this..... var _Selected = Selectedvalue(DynamicMetric[Metric],"Sales") RETURN Switch(_Selected, "Sales", Sum(FactSales[Sales]), "Cost", Sum(FactSales[Cost]), "Profit", Sum(FactSales[Profit])). When I run this against my relatively large model with Dimensions Product, Seller, and Customer it takes 7 seconds. when "Cost" is selected. But when I swap out this measure for just the "Cost" measure... Sum(FactSales[Cost]) it takes 3 seconds. The only difference in dax studio that I can see if the A Callbackid is generated when using the "switch Measure". Note that the switch selected value is directly what I am filtering on per your videos. Can Switch really kill performance this bad?

  • @omarbn92
    @omarbn92 11 місяців тому +1

    Thank you for the video, will row level security on measure option slicer impact performace of switch ?

    • @SQLBI
      @SQLBI  11 місяців тому +1

      It shouldn't.

  • @tejasbrahmbatt5344
    @tejasbrahmbatt5344 2 роки тому

    Would be interesting to see if the fields parameter generates more optimal query plan than switch

    • @SQLBI
      @SQLBI  2 роки тому

      Yes, fields parameter are usually better because they change the query generated by Power BI, making the entire process more efficient. More details here: www.sqlbi.com/articles/fields-parameters-in-power-bi/

  • @Guiburgueir4
    @Guiburgueir4 2 роки тому

    Hi Marco,
    What is your opinion on the new "Field Parameters" slicers compared to this? I not too knowledgeable about the query plan but as far I checked it looks simpler.

    • @SQLBI
      @SQLBI  2 роки тому +2

      For this specific use case Field Parameters are a better and faster solution. However, the article is about SWITCH optimization, and this is a very simple use case. Moreover, Field Parameters works only for Power BI, not in other client (not supported for Analyze in Excel, for example).

  • @GaryMillerUK
    @GaryMillerUK 2 роки тому

    Third of the way through and he's barely mentioned SWITCH yet. I don't have the time for this when I'm working. Does the average person need to see all this under the hood stuff? Don't they just want to speed up their queries? I'm sure this is fascinating if you have the time to study it deeply. Maybe I'm not in the intended audience.

    • @SQLBI
      @SQLBI  2 роки тому +1

      This is an advanced article+video that explains how the optimization works. You could quickly scan the related article to see the differences in code in a few seconds. You can find the link in the video description.