Forum Discussion

Lauraeire_81's avatar
Lauraeire_81
Icon for Helper I rankHelper I
1 year ago
Solved

DAX help on category

Hi  I am looking to display the Countries listed depending on what food items are selected in a slicer (where multiple options can be selected). Say 'Hot Dogs', 'Corn dogs' and 'Stew' are selected,...
  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi Lauraeire_81 ,

     

    Use the following DAX to create a new table:

    Table 2 = VALUES('Table'[Countries])

     

    Create a relationship between the two tables:

     

    Create a measure:

    Measure =
    VAR _currentCT =
        SELECTEDVALUE ( 'Table 2'[Countries] )
    VAR _values =
        VALUES ( 'Table'[Countries] )
    RETURN
        IF (
            SELECTEDVALUE ( 'Table 2'[Countries] )
                IN _values && ISFILTERED ( 'Table'[Countries] ),
            "'"
                & CONCATENATEX (
                    FILTER ( 'Table', 'Table'[Countries] = _currentCT ),
                    'Table'[Food],
                    " and "
                ) & "' found in '" & _currentCT & ". " & "Count of "
                & COUNTROWS ( FILTER ( 'Table', 'Table'[Countries] = _currentCT ) ),
            IF ( NOT ISFILTERED ( 'Table'[Countries] ), "'Please select an option'" )
        )

     

    Drag the fields of Table2 to the table visual object, the page effect is as follows:

     

    I have tested it and found that select all and select no object is one case, to show all cases when select all. I have a workaround: I can drag the “Table” table's countries field and count measure to the table's visual object, save the slicer select all case as a bookmark, and insert a button. Insert a button and set the action of the button to this bookmark.

     

    The pbix file is attached.

     

    If you have any other questions please feel free to contact me.

     

    Best Regards,
    Yang
    Community Support Team

     

    If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
    If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!