Using OR conditions between slicers in DAX

Sdílet
Vložit
  • čas přidán 30. 07. 2024
  • How to implement a logical OR condition between two slicers of a Power BI report, or of a PivotTable in Excel.
    By default, when relying on more than one slicer they are considered in an AND condition. This video+article explains how to change this behavior using DAX.
    Article and sample download: sql.bi/66373?aff=yt
    How to learn DAX: www.sqlbi.com/guides/dax/?aff=yt
    The definitive guide to DAX: www.sqlbi.com/books/the-defin...
  • Věda a technologie

Komentáře • 79

  • @reneglaus2476
    @reneglaus2476 Před 3 lety +1

    Within 20 minutes I learned more than the last 6 months! This is a real eyeopener. Great, Thank you very much.

  • @stevenfortier1453
    @stevenfortier1453 Před 3 lety +5

    Wow, such a great video Alberto, I really like your way of teaching by starting with a first version of the measure that most of the people can come up with then improve and explaining what are the drawbacks of each technique.
    Thank you!

  • @igordemetriusalencar5861
    @igordemetriusalencar5861 Před 3 lety +5

    Absolutely amazing. I don't even know how to thank you, this will help me a lot in my current power bi project.

  • @gavclark66
    @gavclark66 Před 3 lety +1

    Amazing ! Brilliant demonstration of different ways to calculate the same thing ... but more importantly how to think when writing DAX !

  • @michaelmays9415
    @michaelmays9415 Před 3 lety +1

    Great video! I love how you show the different solutions - it really makes me think about functions I don’t know as well

  • @lukeminikoski
    @lukeminikoski Před 3 lety +2

    I've expended a lot of hours trying make OR working on my measures, it works, but with a lot of limitations :) Thank's, thank's a lot!

  • @jijanice7153
    @jijanice7153 Před 3 lety +2

    Amazing! Cannot stop following your videos and courses! Thanks a million!

  • @nishantkumar9570
    @nishantkumar9570 Před rokem +1

    Loved Set approach and it can only come from sql background.
    Thank you so much for the clarity.
    You're awesome!

  • @paulasturla6541
    @paulasturla6541 Před 3 lety +1

    Fabulous! Thank you for make us see this options so clearly!

  • @argokusumandani9773
    @argokusumandani9773 Před 3 lety +1

    Thank you Sir!
    I am happy that i learn DAX directly from the Grand Master of DAX.
    🎉

  • @eugeneniemand
    @eugeneniemand Před 3 lety +2

    Thanks this was really informative and just shows that you can obtain the same result in many different ways. There is not right or wrong, just different

  • @10ozGold
    @10ozGold Před 3 lety +1

    Excellent explanations Alberto. You're a genius.

  • @ceciliocbaroperez8815
    @ceciliocbaroperez8815 Před 3 lety +1

    Fantastic way of explaining. Great job! Thanks for sharing!

  • @UU-ry6gt
    @UU-ry6gt Před 3 lety +1

    Amazing! You just woke up a detective inside, inspiring to try more and more. I wish I had a teacher like you in school ;)

  • @DanielTavares29
    @DanielTavares29 Před 3 lety +1

    Wow!!! Such a nice approach for learning DAX
    👏👏👏

  • @stevennye5075
    @stevennye5075 Před 3 lety +1

    Excellent explanation, I liked seeing the different ways to solve a problem, too often a single solution is presented and it doesn't examine alternatives.

  • @mnowako
    @mnowako Před 3 lety +1

    Excellent lesson. Thank you Master!

  • @NaraMeerammaTrust
    @NaraMeerammaTrust Před 3 lety +1

    super. what an excellent video with various ways to achieve the goal. I loved it. SOOOOOO helpful practically. I have more options now to implement if client requires.

  • @marceloabbiatiprado4460
    @marceloabbiatiprado4460 Před 3 lety +1

    You deserved more likes and viewers man. Ty for the lesson.

  • @inkuban
    @inkuban Před 3 lety +1

    I need to give this guy a hug!

  • @usmantariq3634
    @usmantariq3634 Před 3 lety +1

    Thx for detailed explanation. Appreciated.

  • @ashishmohan4707
    @ashishmohan4707 Před 3 lety +1

    Hi Alberto Ferrari
    You are amazing.
    I like your way of learning and content deliverable and really really amazing.
    Very big thanks to share with your useful deliverable.
    i used your all logic in my day to day work.
    your blank row logic is very useful and add-columns+Generate+Row

  • @Kmsbi
    @Kmsbi Před 3 lety +1

    You have always wonderful DAX Code :)

  • @tonildg9822
    @tonildg9822 Před 3 lety +1

    Thanks for your great videos

  • @rick_.
    @rick_. Před 3 lety +1

    Excellent video! As to which one is best? My preference is always to start with simplest to understand/maintain, only using more complex or otherwise sophisticated queries if warrented by performance.

  • @senasolak3007
    @senasolak3007 Před 2 lety +2

    such a great explanation! Thank you very much :) I have some questions about it, I have to implement a dashboard that contains the distinct number of customers with 27 slicers (categorical and continuous) and I want to add an AND/OR slicers in it. What would be the optimal way to do it? Thank you very much in advance :)

  • @SamWanderlust
    @SamWanderlust Před 7 měsíci +1

    Amazing, thx a lot!

  • @mahyartalehfirooz8946
    @mahyartalehfirooz8946 Před 3 lety +1

    Great and amazing, Thanks a lot

  • @arklur3193
    @arklur3193 Před 3 lety +1

    I'm always amazed how much thing you can do in DAX, how can you obtain so many interesting result with it. Loved the video, we can learn a lot from it.
    +1 04:29 - ...You.Are.Missing.A.Space.There!

  • @3danim8r1
    @3danim8r1 Před 3 lety +1

    Great!!!..Sir..

  • @amyperalt
    @amyperalt Před 29 dny +1

    This way is not working for 3 different slicers, Is there any other way to use OR clause with 3 different date filters/slicers

  • @hectorluisgaitan996
    @hectorluisgaitan996 Před 3 lety +1

    Excellent demonstration, very well explained, even though I am Latino

  • @mikem2246
    @mikem2246 Před rokem +1

    Thanks for a very interesting and useful tutorial, it helped me in my work, but the problem I'm having is that when "All" is selected in the slicer, I get an empty table😒
    What i'm missing?

  • @121balu
    @121balu Před 4 měsíci +1

    Is there any hierarchical table, eg if I select the group head name the field of table name should be replaced with FH name and if I select FH name it should be replaced with CH name but the name should be replaced in same table

  • @yangkijin
    @yangkijin Před 2 lety +1

    I appreciate all your video and the training course which I subscribed to
    I have a couple of questions on this contents while I follow your measures.
    1. I got a wrong results when I use a measure of [Units] intead of a column of 'Sales[Quantity]. It would be great if anybody could answer this.
    SUMX(******** ,[Units]) versus SUMX(******** ,Sales[Quantity])

  • @zxccxz164
    @zxccxz164 Před 3 lety +1

    Great. How do combine so you can choose and or over several slicers

  • @sherifffruitfly
    @sherifffruitfly Před 3 lety +2

    Good stuff, but I was hoping for discussion of the big limitation: these only work specifically for Brand and Occupation. Is it possible to construct a "universal OR" measure? Where *whatever* slicers the report-developer puts onto the canvas (i.e. not hard coded ahead of time), the measure returns the OR value for the slicer selections?

    • @SQLBI
      @SQLBI  Před 3 lety +1

      No, unfortunately it is not possible to create code that works with any slicer placed in the report.

  • @umangdbz
    @umangdbz Před 2 lety +1

    Awesome

  • @DanielWeikert
    @DanielWeikert Před 3 lety +2

    Great channel, great video. The crossjoin solution naturally does not seem a good idea to me as it is normally a very "heavy" calculation is it not?
    Also I thought I have seen a video where you dive into the difference using ALL as a table function vs using it as a modifier with or without arguments in calculate? Could you point me to that?
    Best regards

    • @SQLBI
      @SQLBI  Před 3 lety +2

      The crossjoin could be expensive, it depends on the number of unique values you have in the two slicers. However, you might be surprised about the performance, which is quite good even though you have a few thousands of items in one slicer and only a couple of items selected in the other. I suggest you try and benchmark it.
      You probably want the videos in this playlist: czcams.com/play/PLU6II7MW-aiIees6mrPfdjt9c8noi7P66.html

    • @DanielWeikert
      @DanielWeikert Před 3 lety

      @@SQLBI Thanks a lot appreciate it!

  • @ClubSoundsForever
    @ClubSoundsForever Před 3 lety

    Are duplicate values as a result of the UNION in example OR #5 kept ? If yes, why does this formula show the correct results?

  • @mshparber
    @mshparber Před 3 lety +1

    Supercool!

  • @anand29091987
    @anand29091987 Před 2 lety +1

    I think it can be simpler. Have taken a simple population table. Happy to have input/suggetsions on same.
    OR = var state = SELECTEDVALUE(Pouplation[States])
    var country = SELECTEDVALUE(Pouplation[Country])
    return CALCULATE(sum(Pouplation[Population]),Pouplation[Country] = country || Pouplation[States] = state)

    • @sunilchauhan9903
      @sunilchauhan9903 Před 7 měsíci

      do you think its allow Country=India || State="Alaska'? i mean does it show two rows? its not working in My case. both State and Country from Same table in my case

  • @mojtabafazeli2140
    @mojtabafazeli2140 Před 3 lety +1

    Hello, thank you for your very good and strong tutorials ... it is possible to put the database that you use for training for download so that we can use it according to your training .... Thank you very much.

    • @SQLBI
      @SQLBI  Před 3 lety

      You can download the sample files in related article linked in the description.
      If you want the underlying SQL database, you can find it in the companion content of our book you can download here: www.sqlbi.com/books/the-definitive-guide-to-dax-2nd-edition/ (you don't have to but the book to download the companion content).

    • @mojtabafazeli2140
      @mojtabafazeli2140 Před 3 lety

      @@SQLBI Thank you very much

    • @mojtabafazeli2140
      @mojtabafazeli2140 Před 3 lety

      @@SQLBI Thank you very much.

  • @sunilchauhan9903
    @sunilchauhan9903 Před 7 měsíci

    is it possible for two columns of same table.

  • @jurgenfabender9719
    @jurgenfabender9719 Před 3 lety +1

    Cool 😎

  • @ejazahmedak
    @ejazahmedak Před 3 lety

    The Union will create some duplicates right? It does not appear to affect the calculations though. I am curious as to why that is the case.
    Also, I am not sure how the filtering worked in the SUMMARIZE version of the measure. How does the table that got created on the fly, retain its relationships to the other tables in the model?

    • @SQLBI
      @SQLBI  Před 3 lety +1

      Duplicated values don't affect the filter context.
      SUMMARIZE doesn't lose data lineage in the "groupby" columns!

    • @ejazahmedak
      @ejazahmedak Před 3 lety

      @@SQLBI Thank you for taking the time to respond to my queries.
      Here is a link to a post I wrote back in 2014 to get OR Filtering in Excel. I went with the CROSSPRODUCT approach:
      strugglingtoexcel.com/2014/02/21/permutations-lists-excel/

    • @ejazahmedak
      @ejazahmedak Před 3 lety +1

      @@SQLBI Lovely video.
      It is very apparent that you pour in a lot of effort into coming up with illustrations that showcase exactly how things work with no room for doubt. Very thankful for making these videos free to watch. God Bless!

  • @visheshjjain
    @visheshjjain Před 3 lety

    Could the code be optimized further by using SELECTEDVALUE() for Brand and Occupation?

    • @SQLBI
      @SQLBI  Před 3 lety +1

      You should write "= SELECTEDVALUE...) but it wouldn't be better and would work only with a single selection.
      This implementation works also with multiple selection.

    • @visheshjjain
      @visheshjjain Před 3 lety +1

      @@SQLBI That’s correct. Didn’t think that way. Thanks! 👍🏻

  • @user-qm2xg3zn4n
    @user-qm2xg3zn4n Před 9 měsíci

    Can this work for other kinds of slicers? Like two slicers that are set to "between"?

    • @SQLBI
      @SQLBI  Před 9 měsíci

      You may use a similar technique, but for the between it's easier to use the proper slicer in Power BI

    • @user-qm2xg3zn4n
      @user-qm2xg3zn4n Před 9 měsíci

      @@SQLBI Hi there, thanks for the response. But could you ellaborate? How would I make two between slicers effact the page in an OR manner?

    • @SQLBI
      @SQLBI  Před 9 měsíci

      Between is not an or - by saying "between" you want an AND, like >= 2 AND

  • @abhishekstatus_7
    @abhishekstatus_7 Před 3 lety +1

    Thanks for sharing this Alberto, However I feel the last solution was really good but not sure about the speed when it's comes to heavy data when we have more then 20ML rows ..

    • @SQLBI
      @SQLBI  Před 3 lety +1

      The speed depends on the cardinality of the slicers (e.g. 3 items x 4 items = 12 possible combinations, which is a small number), not on the number of rows you have in the model. But if you use slicers with millions of possible selections each, you certainly have performance issues. Hundreds/thousands of items shouldn't be a big issue if you select just a few items in each slicer.

  • @JoeLee-jk3wi
    @JoeLee-jk3wi Před 3 lety +1

    It is the best approach to learning DAX. Not sure if you can go through some of DAX patterns using the same ppproach.

    • @SQLBI
      @SQLBI  Před 3 lety

      We have videos for DAX Patterns available at www.daxpatterns.com explaining how the patterns work. The goal of those videos is not to teach DAX, they should speed up the ability to customize the formulas assuming the reader already knows DAX.

  • @scottpowell9985
    @scottpowell9985 Před 3 lety

    The solution I jumped to before even watching the video was using three calculates. Final answer equals sum of all brands for the selected occupation PLUS sum of all occupations for the selected brands MINUS sum of selected brands and occupations (to prevent double counting). Wondering how that performs compared to the set operators

    • @SQLBI
      @SQLBI  Před 3 lety +1

      This is valid only for additive measures. The technique shown in the video is measure-agnostic, it also works with non-additive measures (like DISTINCTCOUNT, time intelligence, ratios, and others).

    • @scottpowell9985
      @scottpowell9985 Před 3 lety

      @@SQLBI very true, great point!

  • @williamrodriguez2694
    @williamrodriguez2694 Před 3 lety

    Say you wanted to filter twice on the same column. One can do this with a single filter visual, the issue arises when you have two filter visuals pointing at the same column.
    Reasoning: one filter visual creates a virtual table with both values. Two filter visuals add an "And" between the two values - resulting in nothing...
    For example, you have a start and end date. One visual for start and one for end. If the two filters are filtering the same column... you can't find the max or min of that column...

    • @SQLBI
      @SQLBI  Před 3 lety +1

      You cannot. Two slicers on the same columns cannot be recognized in the DAX measure. You see the result of the two filters.

  • @AmritaGuha1945
    @AmritaGuha1945 Před 3 lety

    Why using Calculatetable and calculate in OR#2 measure?

    • @SQLBI
      @SQLBI  Před 3 lety

      In order to remove the filters existing on the two grouped columns without losing other filters.

  • @xeck
    @xeck Před 3 lety +2

    Insert Meme = "But wait there's more"

  • @milpatel83
    @milpatel83 Před 2 měsíci

    Why not just calculate the units individually, 1 for occupation and one for brand and just add them up? Or maybe I'm missing something...

  • @tommynguyen4253
    @tommynguyen4253 Před 3 lety +4

    Are you sure that it has only 5 solutions???

  • @mercydabbs3330
    @mercydabbs3330 Před 2 lety

    All your trainings what I always keep wondering at is why don't you like giving the solution instead of paying around with different scenarios but providing your solution??

    • @albertoferrari6893
      @albertoferrari6893 Před 2 lety +1

      This is a very interesting question, thanks.
      The reason is that I want to teach how to find a solution, rather than the solution itself. In your daily reporting requirements, you will quite never face the exact same situation I show during the demo. To me, teaching means giving you the tools needed to face any unknown scenario. If I only show one solution, maybe the best one, you will be fine if you face that scenario, but you will be in trouble with a different scenario. If, on the other hand, I teach you how to find a solution, then you will be able to solve any scenario. I know, it is a harder path... nonetheless, much more rewarding at the end.