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
Anonymous
Not applicable

Slicer option multiple conditions

Hi.

 

I have a custom slicer with several options to choose from. I want to create a measure that when I click one (or more) options from the slicer, a map shows the values (count of something for example) of the options I chose. Problem is, that would require a lot of IF statements, correct? 

 

So, IF I chose OPTION 1 (using the CONTAINS function), the COUNT of something value is showed in the map, else IF I chose OPTION 2 display COUNT of something else, etc etc. ... else IF I chose OPTION 1 and OPTION 2, display the COUNT of something and something else, etc etc.  This will take a lot, and if we add more options to the slicers, it will only get larger.

 

How would I solve this? Is there a shorter method to that?

 

Thanks.

1 ACCEPTED SOLUTION

Hi @Anonymous ,

You can create a measure as below and check whether it can get your expected result:

Measure =
VAR _sellist =
    ALLSELECTED ( 'SlicerTable'[colname] )
RETURN
    IF ( "OPTION 1" IN _sellist, COUNT ( 'Table'[A] ), 0 )
        + IF ( "OPTION 2" IN _sellist, COUNT ( 'Table'[B] ), 0 )
        + IF ( "OPTION 3" IN _sellist, COUNT ( 'Table'[C] ), 0 )

In addition, you can refer the content in the following blogs. Hope they can give you some clue or insights...

Dynamic Measure Selection in Power BI

Power BI DAX Dynamic Measures

Change Measures Using a Slicer in Power BI

If the above ones can't help you find the solution, please share some sample data with Text format and your expected result with backend logic and special examples in order to provide you a suitable solution. Thank  you.

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
selimovd
Super User
Super User

Hey @Anonymous ,

 

there is a shorter way. The combination of SWITCH with TRUE gives you a more clear solution.

Like this you can always put the if condition per line and then the result. For example:

Switch Measure =
VAR vSelectedSlicer =
    SELECTEDVALUE( mySlicerTable[mySlicer] )
RETURN
    SWITCH(
        TRUE(),
        vSelectedSlicer = "Option 1", COUNT( myTable[column 1] ),
        vSelectedSlicer = "Option 2", COUNT( anotherTable[column 2] ),
        vSelectedSlicer = "Option 3", COUNT( totallyDifferentTable[column 3] ),
        vSelectedSlicer = "Option 4", COUNT( myTable[column 4] )
    )

 

Read the following article about that:

DAX - The Diabolical Genius of “SWITCH TRUE” | P3 Adaptive

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 
Anonymous
Not applicable

Thank you for quick reply!

 

What if I selected two or three options from the slicer? I would need multiple switch conditions right? Does the SELECTEDVALUE return a list when I click on multiple options?

Hi @Anonymous ,

You can create a measure as below and check whether it can get your expected result:

Measure =
VAR _sellist =
    ALLSELECTED ( 'SlicerTable'[colname] )
RETURN
    IF ( "OPTION 1" IN _sellist, COUNT ( 'Table'[A] ), 0 )
        + IF ( "OPTION 2" IN _sellist, COUNT ( 'Table'[B] ), 0 )
        + IF ( "OPTION 3" IN _sellist, COUNT ( 'Table'[C] ), 0 )

In addition, you can refer the content in the following blogs. Hope they can give you some clue or insights...

Dynamic Measure Selection in Power BI

Power BI DAX Dynamic Measures

Change Measures Using a Slicer in Power BI

If the above ones can't help you find the solution, please share some sample data with Text format and your expected result with backend logic and special examples in order to provide you a suitable solution. Thank  you.

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.