Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
1 year ago
Solved

Bar Graph Color Formatting Help

Hi,

Is there a way on a bar graph to have the top 3 (by greatest value) be green and the remaining bars be black?

 

  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi Anonymous ,

     

    Thanks for your reply.

    I understood your requirement and here's the workaround with a sample.

    In below scenario, we want the bars of Tom, David and Alex are green, and others are black.

    You can use the conditional formatting feature.

    First, create a measure to return the colors.

    Measure = var _rank=RANKX(ALL('Table'),CALCULATE(SUM('Table'[Sale])),,DESC,Dense)
    return IF(_rank<=3,"green","black")

    Second, in the bar chart, go to the visual format, add your measure created under the bar color.

    Select the measure under Field value style and click OK. Below is the result.

    Reference:

    Apply conditional table formatting in Power BI - Power BI | Microsoft Learn

    RANKX function (DAX) - DAX | Microsoft Learn

     

     

    Best Regards,

    Stephen Tao

     

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

     

     

7 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous ,

     

    Thanks for reaching out. I need to confirm that if you want to change the color of the bars in a single bar chart through conditional formatting in a single bar chart. Let's say there's a four-bar in this single bar chart, the first three are green and the fourth is black. Since your screenshot has four bar charts, which confuses me.

     

     

    Best Regards,

    Stephen Tao

     

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

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Sorry. It would be a mulitbar chart and I need to change the bars to highlight the ones that are the top 3.

       

      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi Anonymous ,

         

        Thanks for your reply.

        I understood your requirement and here's the workaround with a sample.

        In below scenario, we want the bars of Tom, David and Alex are green, and others are black.

        You can use the conditional formatting feature.

        First, create a measure to return the colors.

        Measure = var _rank=RANKX(ALL('Table'),CALCULATE(SUM('Table'[Sale])),,DESC,Dense)
        return IF(_rank<=3,"green","black")

        Second, in the bar chart, go to the visual format, add your measure created under the bar color.

        Select the measure under Field value style and click OK. Below is the result.

        Reference:

        Apply conditional table formatting in Power BI - Power BI | Microsoft Learn

        RANKX function (DAX) - DAX | Microsoft Learn

         

         

        Best Regards,

        Stephen Tao

         

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