Sub topic 13
Testing Measures and Fixing Formats That Do Not Appear
This chapter assumes you can build table, matrix, and chart visuals in Power BI Desktop, write simple DAX measures, and find the Format pane. It also assumes you have a color measure such as [Variance Color] wired to a visual with Format by field value.
When a measure-driven format does not appear, the cause is almost always in the measure's output or in how the format is connected. Test the measure first, then check the connection.
Test the measure's output before the format
A visual only applies a color if the measure returns a valid color string for that cell. Put the measure into a plain table visual next to the fields you are formatting, with no formatting applied. You can then read what each row returns.
Add these to a table:
- The row field, such as
Product[Category]. [Total Sales],[Sales Target], and[Variance %].[Variance Color].
Each row should show a hex string such as #2E7D32, or be empty where the variance is blank. If you see something else, fix the measure before touching the Format pane.
To see the inputs of the decision, return the value itself in a temporary measure:
Debug Variance =
VAR v = [Variance %]
RETURN
IF ( ISBLANK ( v ), "blank", FORMAT ( v, "0.0%" ) )Add it to the same table. If a row shows the wrong color, compare it with this value to see which SWITCH branch ran.
Check the connection
If the table shows correct hex strings but the visual is still uncolored, the problem is in the format setup.
- Open the Format pane, find the element (for example Cell elements, then Background color), and select the fx button.
- Set Format style to Field value.
- Under "What field should we base this on?", pick the measure itself, not the column you are formatting.
- Confirm that the measure's output is text. A measure that returns a number will not work as a color.
If you apply a measure to a visual type or element that does not offer fx, such as a field in a visual that has no conditional formatting for that property, no color can be applied there.
Common causes and fixes
| Symptom | Likely cause | Fix |
|---|---|---|
| No color anywhere | Format style is Gradient or Rules, not Field value | Switch the style to Field value and pick the measure |
| No color anywhere | Measure returns an invalid string, such as `2E7D32` without `#` | Return the full `#RRGGBB` string |
| Some cells uncolored | Variance is blank, so the measure returns `BLANK()` | Expected. Change the `ISBLANK` branch if you want a neutral color |
| Totals uncolored | `ISINSCOPE` returns false on the total row | Expected for `[Variance Color (Matrix)]`. Return a color for that level if you want one |
| Wrong colors | `SWITCH ( TRUE (), ... )` branches are in the wrong order | Put the most restrictive test first, as in `v >= 0.05` before `v >= 0` |
| Colors differ from the table | The visual has different filters or a different grouping | Compare using the same fields in the test table |
| Icon does not show | Measure data category is not Image URL, or `#` is not written as `%23` | Set the data category and escape the `#` |
Check the measure itself
Three mistakes account for most wrong colors.
First, compare against the right scale. [Variance %] is a fraction, so five percent is 0.05, not 5.
Second, handle blanks before comparisons. In DAX a blank compares like zero in many cases, so v >= 0 can be true for a blank and color it amber. The test ISBLANK ( v ) must come first in the SWITCH, as in the earlier color measure.
Third, remember that a measure evaluates in the context of each cell. A total row has a different context from a category row, so it may return a different color or none. That is the reason to test in a table that includes the total.
A worked check
Suppose the Furniture row has no target. In the test table you see [Sales Target] blank, [Variance %] blank, and [Variance Color] empty. That matches the design: DIVIDE returned blank and the first SWITCH branch returned BLANK(). The empty cell is correct, so the fix, if you want one, is a design choice: add a neutral gray branch for the blank case.
Exercise
A matrix shows no colors on any row. In a test table, [Variance Color] shows 2E7D32, F9A825, and C62828 for the rows. What is wrong, and how do you fix it?
Show answer
The measure returns hex codes without the leading #, so Power BI does not read them as colors. Change each string in the measure to include it, for example "#2E7D32", then confirm the test table shows the new values.
Exercise
A category with a blank target is colored amber instead of left empty. The SWITCH starts with v >= 0. What change fixes it?
Show answer
Add ISBLANK ( v ), BLANK () as the first condition pair, before any comparison. A blank can pass v >= 0, so the blank test must run first.