Power BI: How to Apply Conditional Formatting to Text Column


Often you may want to apply conditional formatting to strings in a text column in Power BI, such as the following:

Power BI conditional formatting based on text

Fortunately this is easy to do and the following step-by-step example shows how to do so.

Step 1: Import the Data

First, we will import the following dataset into Power BI that contains information about various basketball players:

Step 2: Create New Column

Suppose that we would like to apply conditional formatting to the values in the Team column.

Before we can do so, we must first create a new column with numeric values that correspond to each of the values in the Team column.

To do so, click the Table tools tab, then click the New column icon:

Then type the following formula into the formula bar:

New = SWITCH(
            'my_data'[Team],
            "A", 1,
            "B", 2,
            "C", 3,
            4
            )

This will create a new column named New that contains numeric values that correspond to the text values in the Team column:

Step 3: Insert Table

Next, navigate to the Report View in Power BI and insert the following table:

Step 4: Apply Conditional Formatting to Text Column

To apply conditional formatting to the values in the Team column, click the dropdown arrow next to Team under the Columns label, then hover over Conditional formatting, then click Background color:

In the new window that appears, choose New for What field should we base this on? and then choose Minimum for Summarization, then create four rules that specify what colors to use for each numeric value in the New column:

Once you click OK, conditional formatting will be applied to each of the strings in the Team column:

Power BI conditional formatting based on text

Additional Resources

The following tutorials explain how to perform other common tasks in Power BI:

Power BI: A Simple Formula for “If Contains”
Power BI: How to Write an IF Statement
Power BI: How to Write a Case Statement

Leave a Reply

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