How to Apply Conditional Formatting in Power BI Bar Chart?

Recently, my colleague worked on a Power BI report where the requirement was to change the color of a bar in a bar chart based on its value. We researched and found that we could achieve this by using conditional formatting in the Power BI bar chart. And there are three methods to do it. Let me explain each method with examples.

Conditional Formatting in Power BI Bar Chart

As we know, Conditional formatting in Power BI is a feature that allows us to format visuals based on conditions or rules dynamically.

There are 3 different ways to apply conditional formatting:

  • Gradient/Color Scale
  • Rule
  • Field value

By using these 3 methods, we will see how to format the colors of bars in the bar chart conditionally.

Apply Conditional Formatting in Power BI Bar Chart using Gradient/Color Scale

In this example, I use the sales financials data table (Financial sample.xlsx). You can create a similar Excel file and then follow the steps below.

power bi bar chart show values

Using this data, I create a bar chart that displays sales based on segment.

how to show values in power bi bar chart

Based on the sales value, we will change the color gradient of the ‘Sum of Sales’ value in the Bar chart.

Three parameters—the lowest value, the middle value, and the highest value—will determine the gradient.

Follow the steps below to apply conditional formatting on the Power BI bar chart based on gradient.

1. First, Select the bar chart, open the Format pane, and expand the Bars section. Then click on the fx in the color section.

power bi bar chart color based on value

2. The Conditional Formatting window will open. Here, select the Format style as a Gradient. Select the Sales field in ‘What field should we base this on, ‘and select Sum as Summarization. Next, ‘How should we format empty values‘ as ‘As zero‘.

conditional formatting bar chart power bi

3. Then, in Minimum value, select Custom from the dropdown and enter the value as 10,000,000. Select the color. For the Maximum value select Custom from the dropdown and enter the value as 25,000,000. Also, you can enable the middle value by checking the box of Add a middle color. Then click on OK. You can set the value as per your requirements.

power bi conditional formatting bar chart

4. Now, you can see the color formatting is applied in the Power BI bar chart.

power bi conditional formatting Stacked bar chart

This is the first method to apply condition formatting in a bar chart.

Apply Conditional Formatting in the Power BI Bar Chart using the Rules

In the first method, we only added three parameters, where we added value, but here, we can add more than that. Let’s see how I do.

Here, we use the same bar chart, which shows sales based on segment.

how to show values in power bi bar chart

1. Similarly, select the bar chart, open the Format pane, and expand the Bars section. Then click on the fx in the color section.

power bi bar chart conditional formatting

2. Now, the Conditional formatting window will open. Here, select the Format style as a Rule. Select the Sales field in ‘What field should we base this on, ‘and select Sum as Summarization.

power bi bar chart color by category

3. Next, we set our rule. To add a new rule, click the +New rule button. I added the rules below, which you can add based on your requirements.

  • If the value >= 0 [Number] and < 10000000[Number], then choose the color.
  • If the value >= 10000000 [Number] and < 20000000[Number], then choose the color.
  • If the value >= 20000000 [Number] and < 30000000[Number], then choose the color.
  • If the value >= 30000000 [Number] and < 50000000[Number], then choose the color.
  • If the value >= 50000000 [Number] and < Max[Number], then choose the color.
  • Then click on OK.
conditional formatting power bi bar chart

4. Check the below screenshot. After applying conditional formatting, our bar chart looks like this.

power bi conditional formatting bar chart based on rule

Apply Conditional Formatting in the Power BI Bar Chart using the Field Value

Here, the field value is nothing but a measure we create. Inside the measure, we define a condition that changes the color based on whether it is met. Let’s see how I do.

Here, we use the same bar chart, which shows sales based on segment.

how to show values in power bi bar chart

1. Now, we need to create the measure. To do this, click on the “New measure“. Then, write the below measure in the formula box:

SalesColor = SWITCH(TRUE(),
SUM(financials[ Sales]) <= 20000000, "Red",
SUM('financials'[ Sales]) <= 1000000000, "Yellow",
"Green")
power bi bar chart color based on value

This measure states that:

  • If the sales amount is less than 20000000, then the bar color will be red.
  • Else if sales amount is less than 1000000000, then the bar color yellow.
  • Otherwise green

2. Select the bar chart, open the Format pane, and expand the Bars section. Then click on the fx in the color section.

power bi bar chart conditional formatting

3. Now, the Conditional Formatting window will open. Here, select the Format style as Field value. Then, select the measure (e.g., SalesColor) from the table under “What field should we base this on.” Finally, click OK.

power bi change color of bar chart

4. Now, you can see that conditional formatting is applied to the bar chart in Power BI.

power bi stacked bar chart color by category

These are the three ways we can apply conditional formatting to a Power BI bar chart. I hope you understand. As a bonus, conditional formatting allows us to change the bar color and the chart background color, border color, shadow color, text color, gridlines, title background color, and more.

You may also like:

>

Build a High-Performance Project Management Site in SharePoint Online

User registration Power Apps canvas app

DOWNLOAD USER REGISTRATION POWER APPS CANVAS APP

Download a fully functional Power Apps Canvas App (with Power Automate): User Registration App

Power Platform Tutorial FREE PDF Download

FREE Power Platform Tutorial PDF

Download 135 Pages FREE PDF on Microsoft Power Platform Tutorial. Learn Now…