Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Dynamic label on certain selection in Dax

Hi all,

 

I have a filter on my report with colors:

Colors:
Blue
Red
Purple
Yellow
Grey
Black

Now I want to create a dynamic label which only focusses on the color "Blue". So if the color Blue is selected (individually or in all selected) I want the card to display: "Blue included" and if the color Blue is deselected and want it to show "Blue excluded"

Does anyone has a smart way to do this in Dax?

Many thanks!

  • Anonymous's avatar
    Anonymous
    5 years ago

    Hi Anonymous ,

     

    Try this measure

    Measure =
    IF (
        NOT ( ISFILTERED ( 'Table'[Colors] ) ),
        "Blue excluded",
        IF (
            "Blue" IN ALLSELECTED ( 'Table'[Colors] ),
            "Blue included",
            "Blue excluded"
        )
    )
    

     

     

    Best Regards,

    Stephen Tao

     

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

4 Replies

  • HI Anonymous ,

     

    I am assuming that the COLOR is a column in your dataset as you haven't provided any details on that.

    This can be done by creation a measure calculation for the label:

     

    labelCalc = 

    var val1 = SELECTEDVALUE(tablename[color])

    RETURN

    SWITCH

    (

     TRUE(),

    val1 = "Blue", "Blue included", "Blue excluded"

    )

     

    Replace tablename[color] in the above DAX with your tablename and column name.

     

    Thanks,

    Pragati

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi Pragati, 

       

      Thanks for your help!
      Just one remaining question: if there is no selection made in the filter (so all colors included) the label does not show "Blue included", do you have a way to do this?

       

      Many thanks!

      • Pragati11's avatar
        Pragati11
        Icon for Super User rankSuper User

        HI Anonymous ,

         

        Yes you can modify your DAX as follows to handle that scenario:

        labelCalc = 

        var val1 = SELECTEDVALUE(tablename[color])

        RETURN

        SWITCH

        (

         TRUE(),

        val1 = "Blue", "Blue included", 

        val1 != "Blue", "Blue excluded",  "Blue included"

        )

         

        See if the above modified DAX works.

         

        Thanks,

        Pragati

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous ,

     

    Try this measure

    Measure =
    IF (
        NOT ( ISFILTERED ( 'Table'[Colors] ) ),
        "Blue excluded",
        IF (
            "Blue" IN ALLSELECTED ( 'Table'[Colors] ),
            "Blue included",
            "Blue excluded"
        )
    )
    

     

     

    Best Regards,

    Stephen Tao

     

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