Тёмный

Using OR conditions between slicers in DAX 

SQLBI
Подписаться 103 тыс.
Просмотров 31 тыс.
50% 1

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

Наука

Опубликовано:

 

3 июл 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 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.
@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 ;)
@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. 🎉
@jijanice7153
@jijanice7153 3 года назад
Amazing! Cannot stop following your videos and courses! Thanks a million!
@10ozGold
@10ozGold 3 года назад
Excellent explanations Alberto. You're a genius.
@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
@paulasturla6541
@paulasturla6541 3 года назад
Fabulous! Thank you for make us see this options so clearly!
@ceciliocbaroperez8815
@ceciliocbaroperez8815 3 года назад
Fantastic way of explaining. Great job! Thanks for sharing!
@gavclark66
@gavclark66 3 года назад
Amazing ! Brilliant demonstration of different ways to calculate the same thing ... but more importantly how to think when writing DAX !
@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!
@DanielTavares29
@DanielTavares29 3 года назад
Wow!!! Such a nice approach for learning DAX 👏👏👏
@mnowako
@mnowako 3 года назад
Excellent lesson. Thank you Master!
@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.
@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
@inkuban
@inkuban 3 года назад
I need to give this guy a hug!
@usmantariq3634
@usmantariq3634 3 года назад
Thx for detailed explanation. Appreciated.
@marceloabbiatiprado4460
@marceloabbiatiprado4460 3 года назад
You deserved more likes and viewers man. Ty for the lesson.
@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.
@tonildg9822
@tonildg9822 3 года назад
Thanks for your great videos
@Kmsbi
@Kmsbi 3 года назад
You have always wonderful DAX Code :)
@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
@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!
@mahyartalehfirooz8946
@mahyartalehfirooz8946 3 года назад
Great and amazing, Thanks a lot
@SamWanderlust
@SamWanderlust 6 месяцев назад
Amazing, thx a lot!
@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
@hectorluisgaitan996
@hectorluisgaitan996 3 года назад
Excellent demonstration, very well explained, even though I am Latino
@3danim8r1
@3danim8r1 3 года назад
Great!!!..Sir..
@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.
@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?
@umangdbz
@umangdbz 2 года назад
Awesome
@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 :)
@mshparber
@mshparber 3 года назад
Supercool!
@zxccxz164
@zxccxz164 3 года назад
Great. How do combine so you can choose and or over several slicers
@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.
@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
@amyperalt
@amyperalt День назад
This way is not working for 3 different slicers, Is there any other way to use OR clause with 3 different date filters/slicers
@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])
@jurgenfabender9719
@jurgenfabender9719 3 года назад
Cool 😎
@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: ru-vid.com/group/PLU6II7MW-aiIees6mrPfdjt9c8noi7P66
@DanielWeikert
@DanielWeikert 3 года назад
@@SQLBI Thanks a lot appreciate it!
@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.
@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.
@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?
@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.
@sunilchauhan9903
@sunilchauhan9903 6 месяцев назад
is it possible for two columns of same table.
@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!
@xeck
@xeck 3 года назад
Insert Meme = "But wait there's more"
@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!
@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! 👍🏻
@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.
@user-qm2xg3zn4n
@user-qm2xg3zn4n 8 месяцев назад
Can this work for other kinds of slicers? Like two slicers that are set to "between"?
@SQLBI
@SQLBI 8 месяцев назад
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 8 месяцев назад
@@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 8 месяцев назад
Between is not an or - by saying "between" you want an AND, like >= 2 AND
@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.
@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.
@tommynguyen4253
@tommynguyen4253 3 года назад
Are you sure that it has only 5 solutions???
@milpatel83
@milpatel83 Месяц назад
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...
Далее
Bidirectional relationships and ambiguity
14:02
Просмотров 99 тыс.
Row Context in DAX
20:42
Просмотров 93 тыс.
Rope climb tutorial !! 😱😱
00:22
Просмотров 2,2 млн
Apply AND Logic to Multiple Selection in DAX Slicer
12:50
When to use KEEPFILTERS over iterators
18:56
Просмотров 47 тыс.
Using ALLEXCEPT vs ALL VALUES
13:35
Просмотров 52 тыс.
DAX Fridays #204: Slice by the results of a measure
10:59
DAX Summarization Tricks in Power BI
12:51
Просмотров 20 тыс.
Propagating filters using TREATAS in DAX
19:18
Просмотров 43 тыс.
Using GENERATE and ROW instead of ADDCOLUMNS in DAX
12:26
Understanding data lineage in DAX
18:14
Просмотров 29 тыс.
Кто производит iPhone?
0:59
Просмотров 463 тыс.