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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
SuryaDave
Helper I
Helper I

Conditional Colouring Bar Chart

Hello Experts,

 

I am stuck with something that I guess is not too complex but I am not able to figure out.

 

Basically, I have bar chart where I want to colour bars conditionally. 
Pic 1.png

 

So, what I want to happen is  
(a) Colour for State Level should always stay Green

(b) Pink colour should be applied to whatever has been selected in Organisation slicer. 

Problem :
I thought that I would solve it just through selected value but because in my barchart I have turned off interaction from Organisation slicers to ensure all organisations are diplayed on the chat - it doesn't recognise the single selection in selected value - hope it make sense. 

 

it would be great if anyone can assist.

 

I am attaching Power BI file - file has 2 tabs - one with the original data and one with the example where I have hardcoded colours to show what I am trying to achieve.

 

Thanks

PBI_File_ConditionalColouring 

2 ACCEPTED SOLUTIONS
Ritaf1983
Super User
Super User

Hi @SuryaDave 
You can use disconected table of organization , and keep the visual interactions.

Ritaf1983_0-1753251149480.pngRitaf1983_1-1753251186513.png

+ this tablle will be the source for the slicer :

Ritaf1983_2-1753251250065.png

For the color you can use a DAX with the wanted color HEXA codes ( i used names  of colors just to show the logic) :

Color =

if (SELECTEDVALUE(Sheet1[Organisation])= "State Level", "Green",

IF(SELECTEDVALUE(Sheet1[Organisation]) IN( VALUES(Organization[Organisation])),"Pink", "Grey" ))
Ritaf1983_3-1753251392632.png

Result :

Ritaf1983_4-1753251438801.png

The pbix is attached

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

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

View solution in original post

Hi @SuryaDave 
You can use the method of "play role relationship".
Create a inactive relationship without your table and organizations :

Ritaf1983_0-1753767006973.png

For other visualizations that need to be filtered you can use the "Userelationship" function to make the relationship active .
Like :

Filtered_measure = CALCULATE(AVERAGE(Sheet1[Avg Values]),USERELATIONSHIP(Organization[Organisation],Sheet1[Organisation]))
Result:
Ritaf1983_1-1753767189061.png

The updated pbix is attached

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

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

View solution in original post

19 REPLIES 19
v-kpoloju-msft
Community Support
Community Support

Hi @SuryaDave,

Thank you for reaching out to the Microsoft fabric community forum.  I reproduced the scenario, and it worked on my end. I used my sample data and successfully implemented it.

vkpolojumsft_0-1753331528570.png

 


I am also including .pbix file for your better understanding, please have a look into it:

Hope this helps clarify things and let me know what you find after giving these steps a try happy to help you investigate this further.

Thank you for using the Microsoft Community Forum.

 

Hi @SuryaDave,


Just checking in to see if the issue has been resolved on your end. If the earlier suggestions helped, that’s great to hear! And if you’re still facing challenges, feel free to share more details happy to assist further.

Thank you.

Hi, no it has not resolved yet ..

@Ashish_Mathur  requested for more information that I shared yesterday ....so I waiting for his response & hopefully with his expertise I might get suggestion that can help in resolving my query / question ....

v-kpoloju-msft
Community Support
Community Support

Hi @SuryaDave,

Thank you for posting your query in Microsoft Fabric Community Forum. Also, thanks to @Ritaf1983@burakkaragoz, for those inputs on this thread.

Has your issue been resolved? If the response provided by the community members @Ritaf1983@burakkaragoz, addressed your query, could you please confirm? It helps us ensure that the solutions provided are effective and beneficial for everyone.

Thank you.

Ritaf1983
Super User
Super User

Hi @SuryaDave 
You can use disconected table of organization , and keep the visual interactions.

Ritaf1983_0-1753251149480.pngRitaf1983_1-1753251186513.png

+ this tablle will be the source for the slicer :

Ritaf1983_2-1753251250065.png

For the color you can use a DAX with the wanted color HEXA codes ( i used names  of colors just to show the logic) :

Color =

if (SELECTEDVALUE(Sheet1[Organisation])= "State Level", "Green",

IF(SELECTEDVALUE(Sheet1[Organisation]) IN( VALUES(Organization[Organisation])),"Pink", "Grey" ))
Ritaf1983_3-1753251392632.png

Result :

Ritaf1983_4-1753251438801.png

The pbix is attached

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

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

Hi @Ritaf1983  I had a look at your solution & it is doing exactly what I described as my problem. However, what I realised is, I forgot to mention in my post that in  my real world problem scenario - the "organisation" slicers is actually being used to filter other charts. 

In the solution that you suggested, "organisation" slicers is being used to dynamically change the colour instead of filtering / slicing organisation. 

Do you have any other suggestion / solution that can achieve both ? I mean a slicer that can filter organisation as well as bar chart changing colour based on selected value in that "organisation" slicer ?

 

Thanks 

Hi @SuryaDave 
You can use the method of "play role relationship".
Create a inactive relationship without your table and organizations :

Ritaf1983_0-1753767006973.png

For other visualizations that need to be filtered you can use the "Userelationship" function to make the relationship active .
Like :

Filtered_measure = CALCULATE(AVERAGE(Sheet1[Avg Values]),USERELATIONSHIP(Organization[Organisation],Sheet1[Organisation]))
Result:
Ritaf1983_1-1753767189061.png

The updated pbix is attached

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

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

Awesome !! Thanks

Happy to help 💌

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

Hi,

Because of the disconnected what is it that you want to do but are unable to do?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

hi @Ashish_Mathur  - thanks for your response and question ...

So, basically, in comparing it with my real world scenario, assume that I have few product categories for each city, so that organisation slicer will also filter another chart which has products listed. 

So, that orgnisation slicer selection should change colour of bar chart and also same filter should also filter another to only display products for the city that has been selected through organisation slicer - hope that makes sense ...

Hi,

Share the download link of the powerBI file with a 2 visual set up and via a text box, just narrate the requirement there.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi Ashish, 
Apologies for late response - was travelling 

Please see attached updated PBI file with tab explanation that shows the problem statement and solution that I am trying to work out - hope this will give you better clarity ...
thanks again ...

Surya

 

Updated_File_Conditional_ColouringBarChart 

This will have to be done with a disconnected table.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

thanks Ashish for response & again appreciate you sparing time to share  your expertise.

I will just accept answer of Rita as official solution as Rita was the first person suggesting the same solution. 

 

 hi @Ashish_Mathur  sure - will do it in about next 6 hours - really appreciate your response

Thanks @Ritaf1983  for your response - I will surely try it out and get back to you.

burakkaragoz
Community Champion
Community Champion

Hi @SuryaDave ,

Since you have slicer interactions turned off for the bar chart, you need a different approach to detect the selected organisation. Here's the solution:

Create this measure for conditional coloring:

Bar Color = 
VAR SelectedOrgs = 
    CALCULATETABLE(
        VALUES('Sheet1'[Organisation]),
        REMOVEFILTERS('Sheet1'[Metric Name])
    )
VAR SelectedOrgCount = COUNTROWS(SelectedOrgs)
VAR CurrentOrg = MAX('Sheet1'[Organisation])

RETURN
SWITCH(
    TRUE(),
    CurrentOrg = "State Level", "#00B050",  // Always green for State Level
    SelectedOrgCount = 1 && CurrentOrg IN SelectedOrgs, "#FF69B4",  // Pink for selected org
    "#808080"  // Grey for others
)

How to apply it:

  1. Add this measure to your model
  2. In your bar chart, go to Format visual → Columns → Colors
  3. Click the fx icon next to "Default color"
  4. Set "Format by" to "Field value"
  5. Select your "Bar Color" measure

This should work because CALCULATETABLE with REMOVEFILTERS will detect the slicer selection even when visual interactions are turned off.

Let me know if this works for you!


If my response resolved your query, kindly mark it as the Accepted Solution to assist others. Additionally, I would be grateful for a 'Kudos' if you found my response helpful.

This response was assisted by AI for translation and formatting purposes.

@burakkaragoz  appreciate your prompt response however, somehow it is not working.

It highlights state level in green and all other city bar - are pink.  So, it seems like the formula is not correctly picking up selectedvalue 

Let me know if you want me send you the PBI file ? 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Top Solution Authors