A for Analytics

A For Analytics
Conditional Formatting in Power BI

Conditional Formatting in Power bi

Conditional formatting in Tables and Matrixes

Power BI Desktop and Power BI Service Conditional Formatting for Tables and Matrices
Conditional formatting in Power BI enables you to enhance your tables and matrices by specifying customized cell colors, including color gradients, based on field values. You can also represent cell values with data bars, KPI icons, or as active web links. This feature is applicable to both Power BI Desktop and Power BI Service.

How to Apply Conditional Formatting:

Select Visualization: Begin by selecting a Table or Matrix visualization in Power BI Desktop or the Power BI service.

Access Conditional Formatting: In the Visualizations pane, right-click or select the down-arrow next to the field in the Values well that you want to format. Choose
Conditional formatting,” and then select the desired formatting type.

Apply conditional formatting in tables and matrixes

Note: Conditional formatting overrides any custom background or font colors applied to the conditionally formatted cell.

Remove Conditional Formatting: To remove conditional formatting, select “Remove conditional formatting” from the field’s drop-down menu, and then choose the formatting type to remove.

Remove conditional formatting

Conditional Formatting Options:

1. Format Background or Font Color

To format cell background or font color, select Conditional formatting for a field and choose “Background color” or “Font color” from the drop-down menu.

Format background or font color

2. Color by Color Scale

This option allows you to format cell background or font color using a color scale. Specify the field to base formatting on, summarization type, and color scheme.

  1. In the Format style field, choose Gradient in the Background color or Font color dialog box.
  2. Select the field for formatting based on, either the current field or any field with numerical or color data.
  3. Specify the aggregation type under Summarization.
  4. Choose a formatting option for blank values under Default formatting.
  5. Decide whether to use the lowest and highest field values or custom values for the color scheme under Minimum and Maximum.
  6. Select colors for the minimum and maximum values.
    Optionally, add a middle color by checking the box and specify a Center value and color.
Color by color scale

An example table with color scale background formatting on the Affordability column looks like this:

Color by color scale - Weather States

The example table with color scale font formatting on the Affordability column looks like this:

Weather report - Affordability

3. Color by Rules:

Format cell background or font color based on defined rules. Set value ranges and assign colors to each range.

  1. In the Format style field of the Background color or Font color dialog box, choose Rules.
  2. Determine the field for formatting by referring to “What field should we base this on?” and specify the aggregation type with “Summarization.”

Under the Rules option, do the following:

  1. Define one or more value ranges.
  2. Assign a color to each value range.
  3. Each value range consists of an If value condition, an and value condition, and a color.
  4. Cell backgrounds or fonts within each value range will be colored according to the specified color.

For instance, consider the following example with three rules:

Background Color - Affordability

Choosing “Percent” in this dropdown means you’re establishing rule boundaries as a percentage of the total range of values, spanning from the minimum to the maximum. For instance, if the lowest data point is 100 and the highest is 400, using the mentioned rules would result in points below 200 being colored green, those between 200 and 300 as yellow, and any value exceeding 300 as red.

Here’s an example table showcasing background color formatting based on “Percent” in the Affordability column:

rules-based background color formatting based on Percent

4. Color by Rules for Percentages

If the field you’re using for formatting contains percentages, express the numbers in the rules as decimals, which represent the actual values. For instance, use “.25” instead of “25”. Additionally, choose “Number” instead of “Percent” for the number format. For example, if you set a rule as “If the value is greater than or equal to 0 Number and less than .25 Number,” it will identify values less than 25%.

Color by rules for percentages

In this sample table with background color formatting rules applied to the % revenue region column:

  • Values from 0 to 25% are colored red.
  • Values between 26% and 41% are colored yellow.
  • Values at 42% or higher are colored blue.
Color by rules for percentages revenue

5. Color by Color Values

You can format a column’s background or font color using conditional formatting based on:

  • Hexadecimal values: Use 3, 6, or 8-digit hex codes, e.g., #3E4AFF (ensure you include the # symbol at the start).
  • RGB or RGBA values: Specify color with RGB or RGBA, like RGBA(234, 234, 234, 0.5).
  • HSL or HSLA values: Utilize HSL or HSLA values, such as HSLA(123, 75%, 75%, 0.5).
  • Color names: Apply color names like Green, SkyBlue, or PeachPuff.

For example, the table below associates a color name with each state:

Color by color values

To format the Color column based on its field values, select Conditional formatting for the Color field, and then select Background color or Font color.

In the Background color or Font color dialog box, select Field value from the Format style drop-down field.

Background Color - color

An example table with color field value-based Background color formatting on the Color field looks like this:

table with color field value-based Background color formatting

If you also use Field value to format the column’s Font color, the result is a solid color in the Color column:

Field value to format the column's Font color,

6. Color Based on a Calculation

You can create a calculation that outputs different values based on business logic conditions you select. Creating a formula is usually faster than creating multiple rules in the conditional formatting dialog.

For example, the following formula applies hex color values to a new Affordability rank column, based on existing Affordability column values:

Affordability rank column, based on existing Affordability

To apply the colors, select Background color or Font color conditional formatting for the Affordability column, and base the formatting on the Field value of the Affordability rank column.

Background Color - Affordability 2

The example table with Affordability background color based on calculated Affordability rank looks like this:

table with Affordability background color based on calculated Affordability rank

7. Add Data Bars

  1. Click on Conditional formatting for the Affordability field.
  2. From the drop-down menu, choose Data bars.

In the Data bars dialog:

  1. By default, the “Show bar only” option is unchecked, allowing both bars and actual values in the table cells. To display only the data bars, check the “Show bar only” box.
  2. You can define Minimum and Maximum values, choose data bar colors and direction, and set the axis color.
Add data bars

With data bars applied to the Affordability column, the example table looks like this:

data bars applied to the Affordability column

8. Add Icons

To display icons based on cell values:

  1. Choose Conditional formatting for the field.
  2. From the drop-down menu, select Icons.

In the Icons dialog:

  1. Under Format style, opt for either Rules or Field value.

To format using rules:

  1. Select a field for the basis (“What field should we base this on?”).
  2. Specify the Summarization method, Icon layout, Icon alignment, and Icon Style.
  3. Define one or more Rules. For each rule, set conditions with “If valueandand value” conditions and select an icon.

To format based on field values:

  1. Choose a field for the basis (“What field should we base this on?”).
  2. Set the Summarization method, Icon layout, and Icon alignment.
  3. For example, the following illustration demonstrates adding icons based on three rules:
Add icons

Select OK. With icons applied to the Affordability column by rules, the example table looks like this:

With icons applied to the Affordability column by rules

9. Format as Web URLs

If you have a column or measure that contains website URLs, you can use conditional formatting to apply those URLs to fields as active links. For example, the following table has a Website column with website URLs for each state:

Format as web URLs

To make each state name a clickable link to its website:

  1. Click on Conditional formatting for the State field.
  2. Choose Web URL.

In the Web URL dialog:

Under “What field should we base this on?”, select Website, and then click OK.

With Web URL formatting enabled for the State field, each state name now functions as a live link to its respective website. In the example table below, the State column has Web URL formatting, while the Overall rank column has conditional Data bars applied.

Web URL formatting applied to the State field

Totals and Subtotals

You can apply conditional formatting rules to totals and subtotals, for both table and matrix visuals.

You apply the conditional formatting rules by using the Apply to drop-down in conditional formatting, as shown in the following image.

Totals and subtotals

Color-Code Based on Text

In contrast to Excel, you can’t directly assign specific colors to text values like “Accepted”=blue, “Declined”=red, “None”=grey. Instead, you need to create measures that associate these values with colors and then apply formatting based on these measures.

For instance, you can create a measure called StatusColor using SWITCH function:

Afterward, in the Background color dialog box, you can format the Status field based on the values provided by the StatusColor measure.

Color-code based on text

In the resulting table, the formatting is based on the value in the StatusColor field, which in turn is based on the text in the Status field.

formatting is based on the value in the StatusColor field

Considerations and Limitations

  • Conditional formatting may require aggregation or measures to be applied to values.
  • Considerations related to NaN values and printing reports with conditional formatting are mentioned.

Conditional formatting in Power BI is a powerful tool that allows you to make your tables and matrices visually informative and appealing, highlighting important data based on specific conditions or criteria.

Leave a Comment

Your email address will not be published. Required fields are marked *