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
Purva
Regular Visitor

Using Slicer to filter multiple columns with OR Logic

Hello,

 

I have data in belwo format in one of my tables. For each item, there can be multiple Categories, and subcategories-
I want to implement a slicer such that if a user selects a particular category, or subcategory it would give item details, where either the selected category is in cat1, cat2 or cat3, and selected subcategory is in subcat1, subcat2, or subcat3

 

 

ItemCat1SubCat1Cat2SubCat2Cat3SubCat3Other Columns
1AA1BB5   
2BB5AA1BB5 
3GG3GG7BB5 
4XX9BB5PP6 
5PP6PP2   
6KK10K    

 

So, here If user want's to see items for category B, subcategory B5, below items should be displayed:-

Item1, Item2, Item3, Item 4

Could you please suggest the most optimal way to perform this as this is a massive dataset.

 

Thank you in advance!

1 ACCEPTED SOLUTION
Sahir_Maharaj
Super User
Super User

Hello @Purva,

 

Can you please try this DAX for Dynamic Filtering:

SlicerTable = DISTINCT(UNION(SELECTCOLUMNS(YourTable, "CatOrSubCat", YourTable[Cat1]), SELECTCOLUMNS(YourTable, "CatOrSubCat", YourTable[SubCat1]), ...))
ItemFilterMeasure = 
VAR SelectedCatOrSubCat = SELECTEDVALUE(SlicerTable[CatOrSubCat])
RETURN
IF(
    COUNTROWS(
        FILTER(
            YourTable,
            YourTable[Cat1] = SelectedCatOrSubCat ||
            YourTable[SubCat1] = SelectedCatOrSubCat ||
            YourTable[Cat2] = SelectedCatOrSubCat ||
            YourTable[SubCat2] = SelectedCatOrSubCat ||
            YourTable[Cat3] = SelectedCatOrSubCat ||
            YourTable[SubCat3] = SelectedCatOrSubCat
        )
    ) > 0, 1, 0
)

Note: You'll first need to normalize your data by unpivoting the category and subcategory columns


Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution?
➤ Lets connect on LinkedIn: Join my network of 13K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

View solution in original post

1 REPLY 1
Sahir_Maharaj
Super User
Super User

Hello @Purva,

 

Can you please try this DAX for Dynamic Filtering:

SlicerTable = DISTINCT(UNION(SELECTCOLUMNS(YourTable, "CatOrSubCat", YourTable[Cat1]), SELECTCOLUMNS(YourTable, "CatOrSubCat", YourTable[SubCat1]), ...))
ItemFilterMeasure = 
VAR SelectedCatOrSubCat = SELECTEDVALUE(SlicerTable[CatOrSubCat])
RETURN
IF(
    COUNTROWS(
        FILTER(
            YourTable,
            YourTable[Cat1] = SelectedCatOrSubCat ||
            YourTable[SubCat1] = SelectedCatOrSubCat ||
            YourTable[Cat2] = SelectedCatOrSubCat ||
            YourTable[SubCat2] = SelectedCatOrSubCat ||
            YourTable[Cat3] = SelectedCatOrSubCat ||
            YourTable[SubCat3] = SelectedCatOrSubCat
        )
    ) > 0, 1, 0
)

Note: You'll first need to normalize your data by unpivoting the category and subcategory columns


Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution?
➤ Lets connect on LinkedIn: Join my network of 13K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

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.