Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Conditionally format bar chart based on another field value

Hi

 

Does anyone have a way to conditionally format bar chart columns based on another fields value?

 

I would like the colours to be Red and Green based on whether the sum is greater than a target value. 

 

The issue is the target values have changed over time and not static

 

Essentially i want to do;

 

If month value > target value = green

If month value < target value = red

 

I'm sure im missing an easy way to do this but i'm struggling!!

  • Hi Anonymous 

     

    Download example PBIX file

     

    You need to create a measure that sets a color value based on the Target value, presumably this is a measure.

    With that done, you can use the new color measure to set conditional formatting on the columns/bars

     

    Measure to set color based on target value. I'm using Hex color codes, #0F0 is green, #F00 is red.

     

    Column Color = IF(SUM('DataTable'[Value]) >= [Target], "#0F0", "#F00")

     

     

     

    Then apply a CF rule

     

     

     

     

    Regards

     

    Phil

     

6 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Excellent, i new it would be a simple solution!

  • Hi Anonymous 

     

    Download example PBIX file

     

    You need to create a measure that sets a color value based on the Target value, presumably this is a measure.

    With that done, you can use the new color measure to set conditional formatting on the columns/bars

     

    Measure to set color based on target value. I'm using Hex color codes, #0F0 is green, #F00 is red.

     

    Column Color = IF(SUM('DataTable'[Value]) >= [Target], "#0F0", "#F00")

     

     

     

    Then apply a CF rule

     

     

     

     

    Regards

     

    Phil

     

    • FenixDigital's avatar
      FenixDigital
      Frequent Visitor

      Seems this answer was issued for Power BI version 1.9 or so, an seems not to be available in version 2.130 anymore (or it has been moved into another place?) So far I wasn't able to find it.

       

  • OneHotEncoder's avatar
    OneHotEncoder
    Frequent Visitor

    Hi all,

     

    Thanks for the discussion and the answer to this topic.

    I'm currently trying to do a conditional formatting for a similiar use-case.

    I have two bars in a clustered column chart, first is the achieved number, 2nd bar is the target number.

    I would like to add the following conditional formatting: if the achieved number is smaller than the target number, the achieved number bar should be red. Otherwise, the achieved target number bar will be green.

    Both bars should be visible in the clustered column chart.

     

    I setup the measure which does exactly this:

    Achieved number Color = IF('Sheet1'[number_achieved] >= [Sheet1], "#0F0", "#F00")
     
    The issue with your solution is that once I add the 2nd bar to the clustered column chart, it does not work anymore.
    The conditonal formatting for the achieved bars vanish once adding the target bars..
     
    Is there any solution to this?
    • PhilipTreacy's avatar
      PhilipTreacy
      Super User

      Hi OneHotEncoder 

       

      If you can starrt a new topic and attach your PBIX file that'll make it easier to help you.

       

      Regards

       

      Phil

  • TMGinzburg's avatar
    TMGinzburg
    Frequent Visitor

    Has this functionality been removed? I don't have the dynamic option for color for data bars on any of the bar or column visuals.