A table full of numbers is hard to read. Add colour, and the problems jump out: red for regions below target, green for products above margin, a small arrow for growth. In Power BI this is called conditional formatting, and with a DAX measure behind it you can control the colours exactly.
This guide shows every type of conditional formatting in Power BI (background colour, font colour, data bars, icons and chart colours), and how to drive each one with DAX.
Quick answer: Select your table or matrix, open Format visual → Cell elements, pick the field, and switch on Background color or Font color. Click fx and choose Format style: Field value to use a DAX measure that returns a colour such as "#16A34A".
Where to find conditional formatting
For a table or matrix, select the visual and go to Format visual → Visual → Cell elements. Choose the column under Apply settings to, then switch on one of these:
- Background color: fills the cell.
- Font color: colours the number only.
- Data bars: draws a bar inside the cell.
- Icons: adds an arrow, circle or flag.
- Web URL: turns the value into a link.
Each option has an fx button that opens the rules window. There are three format styles:
- Gradient: a colour scale from lowest to highest value.
- Rules: fixed ranges, such as "0 to 50,000 = red".
- Field value: the colour comes from a field or measure. This is the DAX method.
Method 1: Gradient (no DAX)
Choose Background color → fx → Format style: Gradient. Base it on Sum of Sales, set the lowest value to light and the highest to dark. Tick Add a middle color for a three-colour scale, for example red, yellow, green.
Use a gradient when you want a heat-map look and do not need exact thresholds.
Method 2: Rules (no DAX)
Choose Format style: Rules and add conditions:
- If value is greater than or equal to 0 and less than 50,000 → red
- If value is greater than or equal to 50,000 and less than 1,00,000 → amber
- If value is greater than or equal to 1,00,000 → green
Rules can use numbers or Percent. Rules are easy, but they are fixed. If the target changes every month, you have to edit them by hand. That is where DAX helps.
Method 3: Field value with a DAX colour measure
Write a measure that returns a colour as text. Power BI accepts hex codes such as "#DC2626" and colour names such as "Red".
Example 1: Sales vs target
Sales Color =
IF ( [Total Sales] >= [Sales Target], "#16A34A", "#DC2626" )
Now select the Sales column, open Font color → fx, choose Format style: Field value and pick Sales Color under What field should we base this on? Each row turns green or red, and it updates automatically when the target changes.
Example 2: Three bands with SWITCH
Margin Color =
VAR m = [Profit Margin]
RETURN
SWITCH (
TRUE (),
ISBLANK ( m ), BLANK (),
m < 0, "#DC2626",
m < 0.10, "#F59E0B",
"#16A34A"
)
Order matters: SWITCH returns the first true condition. The ISBLANK line keeps empty rows uncoloured. Learn more in IF and SWITCH in DAX.
Example 3: Growth vs last year
Growth Color =
VAR cy = [Total Sales]
VAR py = CALCULATE ( [Total Sales], SAMEPERIODLASTYEAR ( 'Date'[Date] ) )
RETURN
IF ( cy >= py, "#16A34A", "#DC2626" )
This needs a proper date table. See how to create a date table in Power BI.
Example 4: Highlight only the top 3
Top 3 Background =
VAR r = RANKX ( ALLSELECTED ( Product[Product] ), [Total Sales] )
RETURN
IF ( r <= 3, "#E0E7FF" )
Without a third argument, IF returns BLANK, so other rows keep the default background.
Data bars
Switch on Data bars for a column and open fx. Set the positive and negative bar colours and tick Show bar only if you want to hide the number. Data bars work best for one measure with positive values, such as sales by product.
Icons
Switch on Icons → fx, choose Format style: Rules, pick an icon set (arrows, circles, flags) and set the ranges. For example, base it on a growth % measure: up arrow if greater than 0, down arrow if less than 0.
A simple DAX alternative is a text measure that returns an arrow, which you place in its own column:
Trend =
VAR g = [Sales Growth %]
RETURN
IF ( ISBLANK ( g ), BLANK (), IF ( g >= 0, "▲", "▼" ) )
Then colour that column with Growth Color from Example 3.
Conditional colours in bar and column charts
Select the chart and go to Format visual → Bars (or Columns) → Colors and click fx. Choose Field value and pick your colour measure. Each bar now gets its own colour, for example red for products below target.
If you do not see the fx button, check the Legend well. Conditional colours are not available while a legend field is used, so remove it.
Conditional title and card colours
Many text properties also have an fx button. You can set a card's callout value colour, or a visual title's text, from a measure:
Dynamic Title =
"Sales for " & SELECTEDVALUE ( Region[Region], "All Regions" )
Common problems
My colour measure does not appear in the Field value list
The measure must return text. If it returns a number (for example 1 or 0), Power BI will not offer it. Wrap the result in quotes, such as "#16A34A".
The total row is coloured too
In the conditional formatting settings, change Apply to to Values only. Or return BLANK at the total level with IF ( ISINSCOPE ( Product[Product] ), … ).
Colours look different on the total and the rows
The measure is calculated again for the total, so it may land in a different band. This is expected. Hide it with Values only if it confuses users.
Gradient looks almost the same for every row
One very large value stretches the scale. Switch to Rules or set the minimum and maximum to Number instead of the lowest and highest value.
Best practices
- Use colour for meaning, not decoration. Two or three colours are enough.
- Pick colour-blind friendly pairs, such as blue and orange, or add an icon so colour is not the only signal.
- Keep colours in measures, so one change updates every visual.
- Use the same green and red across the whole report.
Frequently asked questions
Can I use a measure for conditional formatting in Power BI?
Yes. Create a measure that returns a colour as text and choose Format style: Field value in the fx window.
Can I conditionally format a whole row in a table?
Yes. Apply the same colour measure to the background of every column in the row. The measure is evaluated per row, so all cells in that row get the same colour.
Does conditional formatting work in a matrix?
Yes, with the same Cell elements settings. Use Apply to to choose values, totals or both.
Which colour formats does Power BI accept?
Hex codes such as "#FF0000" and standard colour names such as "Red" or "Green".
Practice task
Build a matrix with Region on rows and Total Sales and Profit Margin as values. Colour the Profit Margin font with the Margin Color measure from Example 2, add data bars to Total Sales, and set Apply to to Values only. Your matrix should now show the weak regions at a glance.
Next: show the best performers with Top N in Power BI with RANKX and TOPN.
