Forum Discussion
Conditional Colouring Bar Chart
- 1 year ago
Hi SuryaDave
You can use disconected table of organization , and keep the visual interactions.+ this tablle will be the source for the slicer :
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" ))Result :
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.
- 1 year ago
Hi SuryaDave
You can use the method of "play role relationship".
Create a inactive relationship without your table and organizations :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:
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.
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:
- Add this measure to your model
- In your bar chart, go to Format visual → Columns → Colors
- Click the fx icon next to "Default color"
- Set "Format by" to "Field value"
- 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.
- SuryaDave1 year agoHelper I
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 ?