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
Daniel_B
Helper II
Helper II

Change Table Color based on associated slicer selection

Hi All

 

I'm trying to make the colour of a table change based on the associated slicer selection

 

Would I need to create a measure for all of the available selections (in this instance I have 4, positive, negative, mixed and neutral) and a table with free-text which fall under one of those 4 categories

 

For example:

 

Free Text              Sentiment

Blah Blah Blah      Neutral

 

Would I need to create a measure where free-text row = NEUTRAL, add that to the table then set up a conditional format to show if slicer selection = NEUTRAL then table colour = BLUE

 

If that isn't the case, any links/ideas that might guide me on this one


Thanks


Dan_B

 

1 ACCEPTED SOLUTION
MartynRamsden
Solution Sage
Solution Sage

Hi @Daniel_B 


Create a measure similar to below (you'll need to replace the table name with your actual table name):

 

Sentiment Colour = 
VAR SelSentiment = SELECTEDVALUE ( 'Table'[Sentiment] )
VAR Result =
SWITCH (
    TRUE(),
    SelSentiment = "Positive", "Green",
    SelSentiment = "Negative", "Red",
    SelSentiment = "Neutral", "Gray",
    SelSentiment = "Mixed", "Orange"
)
RETURN Result

 

Then, head to the formatting pane of your table visualisation and expand Conditional Formatting.

Select the relevant field and enable 'Background color'.

Click Advanced controls

 

Capture.JPG

 

Select format by 'Field value' and then select your newly created measure.

 

Capture1.JPG

 

You'll then end up with something like this:

 

Capture2.JPG

 

 

 

 

 

You can find more info here: docs.microsoft.com/en-us/power-bi/desktop-conditional-table-formatting 

 

Hope it helps.


Best regards,

Martyn

View solution in original post

4 REPLIES 4
MartynRamsden
Solution Sage
Solution Sage

Hi @Daniel_B 


Create a measure similar to below (you'll need to replace the table name with your actual table name):

 

Sentiment Colour = 
VAR SelSentiment = SELECTEDVALUE ( 'Table'[Sentiment] )
VAR Result =
SWITCH (
    TRUE(),
    SelSentiment = "Positive", "Green",
    SelSentiment = "Negative", "Red",
    SelSentiment = "Neutral", "Gray",
    SelSentiment = "Mixed", "Orange"
)
RETURN Result

 

Then, head to the formatting pane of your table visualisation and expand Conditional Formatting.

Select the relevant field and enable 'Background color'.

Click Advanced controls

 

Capture.JPG

 

Select format by 'Field value' and then select your newly created measure.

 

Capture1.JPG

 

You'll then end up with something like this:

 

Capture2.JPG

 

 

 

 

 

You can find more info here: docs.microsoft.com/en-us/power-bi/desktop-conditional-table-formatting 

 

Hope it helps.


Best regards,

Martyn

@MartynRamsden , thank you so much for that - works perfectly (colours are a bit bolder than I'd like but I can work on that 🙂 )

 

Very Much appreciated

Hi @Daniel_B 

 

No problem!

 

You can replace the names of the colours in the DAX expression with the hex code of any colour you prefer.
There's an example of this towards the bottom of the article I linked to.


Best regards,
Martyn

Anonymous
Not applicable

I think this can be accomplished with conditional formatting. Maybe make a calculated field that has a number (1,2,3,4) based on your slicer selection with an "IF" statement?

 

IF Sentiment = Neutral THEN 0 etc.

 

Then make a conditional format that colors the values red, orange, green, etc based on the calculated field.

 

https://community.powerbi.com/t5/Community-Blog/Conditional-Formatting-in-Power-BI-Tables/ba-p/42799...

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.