Conditional Formatting with a Text Field in Power BI - Excelerator BI

Conditional Formatting with a Text Field in Power BI

One of the things I like about my live, online training courses is that I get to hear great questions from the trenches from people learning DAX and Power BI.  Last week, John asked me how to apply conditional formatting with a Text field (not a numeric field).  I knew it could be done, but it required some brief research before I could give an answer. It is pretty easy to apply conditional formatting on a numeric field – this  feature was added to Power BI some time back. However Microsoft has also added the ability to apply conditional formatting to a Text field too in some circumstances.


To understand the process of configuring this, consider the following simple data table.

I just entered some simple sample data using the “Enter Data” menu option. As you can see Project 2, Project 3 and Project 5 have departments associated with them while Project 1 and Project 4 do not.

Suppose you want to use conditional formatting to highlight (colour code) which of the Projects have Departments associated with them and which do not.

The Method

The high level process is to:

  1. Create a measure that returns a colour as the result
    1. It can be a word, such as blue, red, green
    2. It can be a hex code for a colour, like #40E0D0″, “#FFA07A”
  2. Use conditional formatting and use the measure to apply the formatting on the text as a rule.

Here is the step by step process explained.

To start with, I created a test measure as follows.

Test =
     VAR Dept = SELECTEDVALUE(Projects[Department]) 
     RETURN IF(Dept <> BLANK(), Dept, "No Dept")

Next, I placed a table visual in the report and added  the columns project, department and the test measure.

As you can see, the measure identifies which of the projects have a department and which do not.  So this test measure has the logic required to go to the next step.

Next, I created a new measure [Colour Project], taking the logic from the test measure that I created above and modifying it to output names of colours.  This can be simply achieved by returning hex codes or common names of colours.

Colour Project =
    VAR Dept = SELECTEDVALUE(Projects[Department])
    RETURN IF(Dept <> BLANK(), "#40E0D0", "#FFA07A")
For this I picked up Hex Codes for colours from the site

The next step is to turn on the conditional formatting for the project column so that it is coloured based on the measure [Colour Project] above.

To apply the conditional formatting, I clicked on the down arrow (#1 below) next to project and then on conditional formatting (#2 below) and then on background color (#3 below).

In the background color dialog that appears, select format by field value (#1 below) and based on field color project (#2 below). Click on OK.

The text field “project” is now conditionally formatted by the logic given by the measure [Colour Project] using the chosen Hex Codes.

It is also possible to apply conditional formatting using words, such as “Green” and “Red”.

To illustrate this, I created the measure [Colour Test] based on the logic previously used as follows.

Colour Test =
    VAR Dept = SELECTEDVALUE(Projects[Department])
    RETURN IF(Dept <> BLANK(), "Green", "Red")

Power BI Online Training

Next, I applied the conditional formatting on the original measure [Test] using font color. I used format by color test. And the result is as follows.

A Final Note

It is worth noting that I am using the table visual for this article.  All columns and measures are are placed in the Values section of the visual. Conditional formatting works only when a column or measure is in Values section of a visual. If we use a matrix instead and place project on rows, you cannot apply conditional formatting to that field.

33 thoughts on “Conditional Formatting with a Text Field in Power BI”

  1. Do we have option to put 5 color base on status, in similar manner as example mention 2 color


    Thanks in advance..

  2. Test =
    VAR Dept = SELECTEDVALUE(Table2[Project](Table2[Department])
    RETURN IF(Dept BLANK(), Dept, “No Dept”)

    It is showing an error to me while writing the above measure. Can you please help?

  3. Test =
    VAR Dept = SELECTEDVALUE(Table2[Project](Table2[Department])
    RETURN IF(Dept BLANK(), Dept, “No Dept”)

  4. I have start date and end date.
    Have taken 1 date filter which shows list of months.
    And based on selected month I added measure for calculating date difference in days.
    Now I want to calculate sum of that measure which shows days. So how can I do that ?
    Can you please out with that ?

  5. Hi Matt, I have one column in which I am showing the comparison between the other two column as in if that two columns have same value then new column will show ‘yes’ otherwise ‘no’
    I have to apply conditional formatting on this column if its value is yes then background should be red if no then white
    How can I do it ?

    Thanks ,

    1. First write a measure that defines the colour as follows:
      Column3 Colour = VAR SelectedValue = SELECTEDVALUE(‘Table (2)'[Column3])
      VAR Colour = SWITCH(SelectedValue,
      “Yes”, “Red”,
      “No”, “White”
      RETURN Colour
      Next apply conditional formatting on Column3 based on Field Value and choose the field as measure defined above.

  6. Hi Matt, This is excellent, But I am trying to apply color in same column on 2 values. Can you please share your expert advise how this can be possible?

    Val 1
    Val 2

    I want Val 1 in color red if occur in column and Val 2 in color green if occur in column.


    1. Define a measure as follows:
      Column Colour = VAR SelectedValue = SELECTEDVALUE(‘Table'[Column])
      VAR Colour = SWITCH(SelectedValue,
      “Val1”, “Red”,
      “Val2”, “Green”
      RETURN Colour

      Next, put Column in a Table visual.
      Apply conditional formatting for Column by Field value and then choose Column Colour

    1. Yes, both the background and the font can be set to the same colour using the same measure. I do this all the time to generate “heat maps” where you just see the colour, not the numbers

  7. Hi Everyone, Is there any way to apply conditional formatting on all columns of table at once, rather than applying on every single column separately?

  8. hello, first thanks for your great tutorial. I’ve got an issue expecting a solution. In a matrix visual, how to conditionally format a subcategory in row? Like change its background Color. It seems that BI only support column and value’s conditional formatting… Hope you can help me.

  9. virginia rodriguez

    I would like to know how I should proceed with Power BI when granting access permissions to different users of my company so they can see a report that I make. thank you

  10. virginia rodriguez

    I would like to ask if POWER BI allows you to make a Conditional Format, in which the conditioners are a value> or = instead of a value, something type
    =Switch(E2>=0,8;”text1″; “text2”)

    1. Yes, it is possible to conditionally format with the value >, < or = instead of the value. For e.g. suppose we have another column in the table showing budget for each project. You can conditionally format Project by checking the Budget as follows.

        Color Project by Budget =
        VAR ProjBudget = SELECTEDVALUE(Projects[Budget])
        Return IF(ProjBudget < 1500, "yellow", "pink")
    1. There is currently no way to reference a line in a visual for conditional formatting purposes. This may change – MS is working on expression based formatting across the product. You can already colour the background of a card using an expression (for example). The only option you have is to format each column in the row using the technique I have demonstrated above

    1. Actually, yes. You also can use that in matrix. You can use that in “Conditional formatting”.
      Very useful tips.

Leave a Comment

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

Scroll to Top