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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
NikitaDalela
Helper II
Helper II

Implementing AND/OR logic in Slicers

Hi Folks,

I came across a client requirement today stating the need of Slicers to work with AND/OR logic. The slicers in Power BI by default work by OR logic. So, I created a simple measure in order to implement AND logic. 

Dataset consists of following two tables.

StudentData.JPG

 

 

 

 

 

 

 

 

Now, I want the name of students who opted for both subjects 'Maths' and 'English' and not 'Maths' or 'English' or 'both'. 

1. First of all, I took Subject column values as slicer values and dragged Name and Marks to grid.

2. Now, I created a measure giving me the count of subjects [SubjectCount]

3. Created another measure comparing the count of subjects selected on slicer and that of rows filtered from table. This measure returns 1 when a student has opted for all selected subjects, else 0.

ANDMeasure.JPG

 

 

 

4. Now, we add this measure to filter pane of grid visual such that it's value is greater than 0.

ANDMeasure.JPG

And that's it! This way, the slicer works by AND logic. Please find the snapshot below.

Result.JPG

Do let me know if there is a simpler way to achieve this.

 


Thanks and Regards,
Nikita Dalela | BI Consultant
Nice Software Solutions

1 REPLY 1
Greg_Deckler
Super User
Super User

@NikitaDalela - Right, there are existing solutions for AND slicers, like this one:

https://community.powerbi.com/t5/Quick-Measures-Gallery/Patient-Cohort-AND-Slicer/m-p/391883#M130

 

Also, what it sounds like you implemented is basically the Complex Selector pattern:

https://community.powerbi.com/t5/Quick-Measures-Gallery/The-Complex-Selector/m-p/1116633#M534


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors