Using OR conditions between slicers in DAX

  Рет қаралды 31,215

SQLBI

SQLBI

Күн бұрын

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...

Пікірлер: 79
@reneglaus2476
@reneglaus2476 3 жыл бұрын
Within 20 minutes I learned more than the last 6 months! This is a real eyeopener. Great, Thank you very much.
@gavclark66
@gavclark66 3 жыл бұрын
Amazing ! Brilliant demonstration of different ways to calculate the same thing ... but more importantly how to think when writing DAX !
@jijanice7153
@jijanice7153 3 жыл бұрын
Amazing! Cannot stop following your videos and courses! Thanks a million!
@nishantkumar9570
@nishantkumar9570 Жыл бұрын
Loved Set approach and it can only come from sql background. Thank you so much for the clarity. You're awesome!
@stevenfortier1453
@stevenfortier1453 3 жыл бұрын
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!
@UU-ry6gt
@UU-ry6gt 3 жыл бұрын
Amazing! You just woke up a detective inside, inspiring to try more and more. I wish I had a teacher like you in school ;)
@lukeminikoski
@lukeminikoski 3 жыл бұрын
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!
@michaelmays9415
@michaelmays9415 3 жыл бұрын
Great video! I love how you show the different solutions - it really makes me think about functions I don’t know as well
@igordemetriusalencar5861
@igordemetriusalencar5861 3 жыл бұрын
Absolutely amazing. I don't even know how to thank you, this will help me a lot in my current power bi project.
@argokusumandani9773
@argokusumandani9773 3 жыл бұрын
Thank you Sir! I am happy that i learn DAX directly from the Grand Master of DAX. 🎉
@10ozGold
@10ozGold 3 жыл бұрын
Excellent explanations Alberto. You're a genius.
@DanielTavares29
@DanielTavares29 3 жыл бұрын
Wow!!! Such a nice approach for learning DAX 👏👏👏
@ceciliocbaroperez8815
@ceciliocbaroperez8815 3 жыл бұрын
Fantastic way of explaining. Great job! Thanks for sharing!
@eugeneniemand
@eugeneniemand 3 жыл бұрын
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
@paulasturla6541
@paulasturla6541 3 жыл бұрын
Fabulous! Thank you for make us see this options so clearly!
@stevennye5075
@stevennye5075 3 жыл бұрын
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.
@marceloabbiatiprado4460
@marceloabbiatiprado4460 3 жыл бұрын
You deserved more likes and viewers man. Ty for the lesson.
@inkuban
@inkuban 3 жыл бұрын
I need to give this guy a hug!
@anand29091987
@anand29091987 2 жыл бұрын
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 6 ай бұрын
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
@mnowako
@mnowako 3 жыл бұрын
Excellent lesson. Thank you Master!
@ashishmohan4707
@ashishmohan4707 3 жыл бұрын
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
@NaraMeerammaTrust
@NaraMeerammaTrust 3 жыл бұрын
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.
@usmantariq3634
@usmantariq3634 3 жыл бұрын
Thx for detailed explanation. Appreciated.
@arklur3193
@arklur3193 3 жыл бұрын
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!
@amyperalt
@amyperalt 20 күн бұрын
This way is not working for 3 different slicers, Is there any other way to use OR clause with 3 different date filters/slicers
@tonildg9822
@tonildg9822 3 жыл бұрын
Thanks for your great videos
@mikem2246
@mikem2246 Жыл бұрын
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?
@Kmsbi
@Kmsbi 3 жыл бұрын
You have always wonderful DAX Code :)
@SamWanderlust
@SamWanderlust 7 ай бұрын
Amazing, thx a lot!
@rick_.
@rick_. 3 жыл бұрын
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.
@121balu
@121balu 4 ай бұрын
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
@senasolak3007
@senasolak3007 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 :)
@zxccxz164
@zxccxz164 3 жыл бұрын
Great. How do combine so you can choose and or over several slicers
@mahyartalehfirooz8946
@mahyartalehfirooz8946 3 жыл бұрын
Great and amazing, Thanks a lot
@hectorluisgaitan996
@hectorluisgaitan996 3 жыл бұрын
Excellent demonstration, very well explained, even though I am Latino
@3danim8r1
@3danim8r1 3 жыл бұрын
Great!!!..Sir..
@yangkijin
@yangkijin 2 жыл бұрын
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])
@ClubSoundsForever
@ClubSoundsForever 3 жыл бұрын
Are duplicate values as a result of the UNION in example OR #5 kept ? If yes, why does this formula show the correct results?
@sunilchauhan9903
@sunilchauhan9903 6 ай бұрын
is it possible for two columns of same table.
@sherifffruitfly
@sherifffruitfly 3 жыл бұрын
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 3 жыл бұрын
No, unfortunately it is not possible to create code that works with any slicer placed in the report.
@umangdbz
@umangdbz 2 жыл бұрын
Awesome
@mojtabafazeli2140
@mojtabafazeli2140 3 жыл бұрын
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 3 жыл бұрын
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 3 жыл бұрын
@@SQLBI Thank you very much
@mojtabafazeli2140
@mojtabafazeli2140 3 жыл бұрын
@@SQLBI Thank you very much.
@DanielWeikert
@DanielWeikert 3 жыл бұрын
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 3 жыл бұрын
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: kzbin.info/aero/PLU6II7MW-aiIees6mrPfdjt9c8noi7P66
@DanielWeikert
@DanielWeikert 3 жыл бұрын
@@SQLBI Thanks a lot appreciate it!
@milpatel83
@milpatel83 2 ай бұрын
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...
@mshparber
@mshparber 3 жыл бұрын
Supercool!
@tommynguyen4253
@tommynguyen4253 3 жыл бұрын
Are you sure that it has only 5 solutions???
@visheshjjain
@visheshjjain 3 жыл бұрын
Could the code be optimized further by using SELECTEDVALUE() for Brand and Occupation?
@SQLBI
@SQLBI 3 жыл бұрын
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 3 жыл бұрын
@@SQLBI That’s correct. Didn’t think that way. Thanks! 👍🏻
@ejazahmedak
@ejazahmedak 3 жыл бұрын
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 3 жыл бұрын
Duplicated values don't affect the filter context. SUMMARIZE doesn't lose data lineage in the "groupby" columns!
@ejazahmedak
@ejazahmedak 3 жыл бұрын
@@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 3 жыл бұрын
@@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!
@jurgenfabender9719
@jurgenfabender9719 3 жыл бұрын
Cool 😎
@AmritaGuha1945
@AmritaGuha1945 3 жыл бұрын
Why using Calculatetable and calculate in OR#2 measure?
@SQLBI
@SQLBI 3 жыл бұрын
In order to remove the filters existing on the two grouped columns without losing other filters.
@user-qm2xg3zn4n
@user-qm2xg3zn4n 9 ай бұрын
Can this work for other kinds of slicers? Like two slicers that are set to "between"?
@SQLBI
@SQLBI 9 ай бұрын
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 9 ай бұрын
@@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 9 ай бұрын
Between is not an or - by saying "between" you want an AND, like >= 2 AND
@williamrodriguez2694
@williamrodriguez2694 3 жыл бұрын
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 3 жыл бұрын
You cannot. Two slicers on the same columns cannot be recognized in the DAX measure. You see the result of the two filters.
@mercydabbs3330
@mercydabbs3330 2 жыл бұрын
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 2 жыл бұрын
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.
@JoeLee-jk3wi
@JoeLee-jk3wi 3 жыл бұрын
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 3 жыл бұрын
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 3 жыл бұрын
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 3 жыл бұрын
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 3 жыл бұрын
@@SQLBI very true, great point!
@abhishekstatus_7
@abhishekstatus_7 3 жыл бұрын
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 3 жыл бұрын
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.
@xeck
@xeck 3 жыл бұрын
Insert Meme = "But wait there's more"
Apply AND Logic to Multiple Selection in DAX Slicer
12:50
Row Context in DAX
20:42
SQLBI
Рет қаралды 95 М.
Эффект Карбонаро и нестандартная коробка
01:00
История одного вокалиста
Рет қаралды 9 МЛН
- А что в креме? - Это кАкАооо! #КондитерДети
00:24
Телеканал ПЯТНИЦА
Рет қаралды 7 МЛН
A clash of kindness and indifference #shorts
00:17
Fabiosa Best Lifehacks
Рет қаралды 109 МЛН
Bidirectional relationships and ambiguity
14:02
SQLBI
Рет қаралды 100 М.
When to use KEEPFILTERS over iterators
18:56
SQLBI
Рет қаралды 47 М.
Using GENERATE and ROW instead of ADDCOLUMNS in DAX
12:26
Understanding context transition
18:25
SQLBI
Рет қаралды 65 М.
DAX Fridays #204: Slice by the results of a measure
10:59
Curbal
Рет қаралды 26 М.
Power Query - Avoid "Helper Queries" (+10 Cool Tricks)
18:40
ГОСЗАКУПОЧНЫЙ ПК за 10 тысяч рублей
36:28
Ремонтяш
Рет қаралды 519 М.
Easy Art with AR Drawing App - Step by step for Beginners
0:27
Melli Art School
Рет қаралды 15 МЛН
Look, this is the 97th generation of the phone?
0:13
Edcers
Рет қаралды 4,3 МЛН
Здесь упор в процессор
18:02
Рома, Просто Рома
Рет қаралды 380 М.
САМЫЙ ДОРОГОЙ ЧЕХОЛ! В стиле Mac Pro
0:35
Romancev768
Рет қаралды 146 М.