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
msommerf
Helper III
Helper III

Conditionally format bar chart column colour based on slicer value

I have the following visuals:

Bar colours in BI.png

 

I am looking to change the colour of each bar based on the selection of the Depot slicer.

If depot slicer is Depot 1, the Depot 1 bar is highlighted

If depot slicer is Depot 2, the Depot 2 bar is highlighted

 

Can anyone advise if this is possible with a measure and conditional formatting?

 

Any assistance appreciated.

1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @msommerf ,

 

Try this:

 

1. Create a separate Depot table.

Depot = VALUES ( 'Table'[Depot] )

 

2. Create a Measure like so:

Highlight = IF ( MAX ( 'Table'[Depot] ) = SELECTEDVALUE ( Depot[Depot] ), "Yellow", "Blue" )

 

3. Set conditional formatting of Data color in Clustered column chart.

 

data color.jpg

data color2.jpg

 

4. Test.

data color.gif

For more details, please check the attached PBIX file.

 

 

Best Regards,

Icey

 

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
Icey
Community Support
Community Support

Hi @msommerf ,

 

Try this:

 

1. Create a separate Depot table.

Depot = VALUES ( 'Table'[Depot] )

 

2. Create a Measure like so:

Highlight = IF ( MAX ( 'Table'[Depot] ) = SELECTEDVALUE ( Depot[Depot] ), "Yellow", "Blue" )

 

3. Set conditional formatting of Data color in Clustered column chart.

 

data color.jpg

data color2.jpg

 

4. Test.

data color.gif

For more details, please check the attached PBIX file.

 

 

Best Regards,

Icey

 

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

Hi 

That's fantastic. Is there any way to change the format the axis labels using the slicer in the same way? I want to be able to only show the label of the selected column by changing the font colour of the other labels to white. I tried it in your example file by changing the conditional formatting of the X axis value settings but the only effect was that all three labels changed to yellow when I select Depot 3, they all remained blue when selecting Depot 1 or Depot 2. I guess this is something to do with the Max function in the Highlight measure. It's odd that the conditional formatting behaves differently for different elements in the same chart.

Many thanks

Nigel

Hey Icey, I've implemented your solution and it works great! Thank you for that. I do however have a question. Is it possible to use the slicer as a filter for other visuals? In my model I get a circular reference error when trying to make the relationship. 

 

Thank you!

ZL

amitchandak
Super User
Super User

Create a measure like this

Color Measure = if(Max(Table[Depot] in allselected(Table[Depot])) <today(),"Yellow","Blue")

 

And use field options and measure in conditional formatting

https://docs.microsoft.com/en-us/power-bi/desktop-conditional-table-formatting#color-by-color-values

 

 

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.