Forum Discussion
Conditional Formatting a Bar Chart using a measure
- 7 months ago
The soluton did not work exactly but were useful. I was able to resolve it in a differnet way. This can be closed.
Hi Clockwise , the issue is that the measure you created returns text values ("red" or "green"), while Power BI’s conditional formatting for bar colours requires either:
- Hex colour codes (e.g., #FF0000 for red), or
- Colour names recognised by Power BI, but only when applied correctly through a field-based rule.
Correct approach
You need to:
Ensure the measure returns a valid colour value (hex or recognised name).
Apply it under Data colours → Conditional formatting → Format by → Field value.
Here is an example of a corrected measure:
Bar_Color_PastDue =
VAR PastDue = SELECTEDVALUE('Summary'[Total Past Due])
VAR AvgPastDue = SELECTEDVALUE('Summary'[Average_TotalPastDue])
RETURN
IF(PastDue > AvgPastDue, "#FF0000", "#008000") // Red or Green in HEXSteps in the visual:
- Go to Format → Data colours.
- Turn on Conditional formatting.
- Select Format by → Field value.
- Choose the measure Bar_Color_PastDue.
If this response was helpful in any way, I’d gladly accept a 👍much like the joy of seeing a DAX measure work first time without needing another FILTER.
Please mark it as the correct solution. It helps other community members find their way faster (and saves them from another endless loop 🌀.
I actually did use the conditional formatting by using field value originally and that was the result. But in the Bar section of visual. Is it somewhere else? As it seems I do not see exactly what you put up there in Power BI desktop. Also I tried hex colors. Nothing.
It sounds if Power BI recognizes colors as texts here, I can not tell it too look at as colors.
So much reminds me of Excel when sometimes you can't tell Excel consider the format of column the way I want.
- Clockwise7 months agoHelper I
Upon further checking, the conditional color measure works fine for background color, here is how I did this case,
Select visual, Format Visual -> General -> Effects -> Background.
So why it won't work for bar colors?
Here is how I get to bar colors, Format Visual -> Visual -> Bars