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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

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!

1 ACCEPTED SOLUTION
v-stephen-msft
Community Support
Community Support

Hi @Anonymous ,

 

Try this measure

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

19.png20.png

 

 

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.

View solution in original post

4 REPLIES 4
v-stephen-msft
Community Support
Community Support

Hi @Anonymous ,

 

Try this measure

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

19.png20.png

 

 

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.

Pragati11
Super User
Super User

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

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

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!

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

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.