Conditional formatting in Power BI: gradients and rules

How conditional formatting in Power BI colours cells, columns, titles and text by data, the three format styles (gradient, rules, field value), data bars and icons in tables, theme colour names like good and bad in DAX, and the traps of colour.

Short answer: conditional formatting sets a colour, an icon or a bar from the data. Anywhere you see the fx button in the format pane (column colours, font colours, backgrounds, titles, borders), you can pick one of three format styles: Gradient (a colour scale between a minimum and maximum), Rules ("if the value is below 0, red") or Field value (a measure returns the colour itself). Tables and matrices add data bars, icons and web URLs. A measure can return a hex colour, or a theme colour name such as good, bad or neutral.

A table of 30 numbers takes a minute to read. The same table with the three red cells that matter takes a second. Colour used for one message per visual turns a report into an alert; colour everywhere turns it into noise.

The short video below shows how to pick colours everyone can read, including people with colour blindness, and why colour should never carry the meaning alone.

Nothing loads from YouTube until you press play. Then Google receives your IP address and may set its own storage. Narrated with an AI-generated voice. Privacy

What can be formatted?

ElementOptions
Table and matrix cellsbackground colour, font colour, data bars, icons, web URL
Chart columns, bars, lines, markerscolour (fx)
Card callout and reference labelsfont colour, background
Visual title, subtitle, borderscolour, and the title text itself (field value)
Shapes, buttons, textfill, text colour
Where conditional formatting applies

Which format style should you use?

StyleHow it decidesUse for
Gradienta colour scale from the lowest to the highest value, optional centreheatmaps, "more is darker"
Rulesranges of values or percentages map to coloursthresholds: below target, near, above
Field valuea measure or column returns the colourany logic you can write in DAX

Microsoft's column chart example shows all three: a gradient on sales variance (red for low, blue for high), rules on a status measure, and a field value measure Color status = IF([This Year Sales] > 2000000, "#200AE8", "#F00938").

How do you write a colour measure?

Return a hex code, a colour name, or a theme colour name. Theme names keep the report consistent when the theme changes:

Target Status Colour =
VAR Attainment = DIVIDE ( [Revenue], [Revenue Target] )
RETURN
    SWITCH (
        TRUE (),
        ISBLANK ( Attainment ), BLANK (),
        Attainment >= 1, "good",
        Attainment >= 0.9, "neutral",
        "bad"
    )

With Field value, Power BI uses the current theme's good, neutral and bad colours. Returning BLANK() leaves the default colour. For hex codes, use "#1A9E75"-style strings.

How do data bars and icons work?

In a table or matrix, open the arrow next to a measure in the well, Conditional formatting:

  • Data bars: a bar in the cell, scaled from the lowest to the highest value (or fixed minimum and maximum), with separate colours for positive and negative, and Show bar only to hide the number.
  • Icons: arrows, traffic lights or shapes by rules, placed left or right of the value; or a measure that returns an icon name.
  • Apply to: values only, values and totals, or totals only.

A rule-based icon for change against last year: up arrow above +2%, sideways between -2% and +2%, down arrow below -2%.

What goes wrong?

  • Colour on everything. Formatting every column means none stands out; format the one column that carries the message.
  • Red and green only. About one in twelve men has trouble telling red from green; add icons or use blue and orange.
  • Gradients across totals. A total row in a gradient is the darkest cell and dominates; apply to values only.
  • Hex codes everywhere. A rebrand means editing every measure; return theme names (good, bad, neutral) or keep colours in one measure.
  • Blank cells coloured as zero. A gradient may treat blanks as the minimum; decide in the dialog how to format blanks.

Where can you check this?

Where do you start?

Write one status measure that returns good, neutral or bad, and use it with Field value on the visuals where the status matters. Report themes set what good, neutral and bad look like.

Keep reading

More from the blog.

Every post

Next

Building this? Say hello.

A question about this post, a pattern you would build differently, or the next thing you want written out: Behnia reads every message.