Sub topic 12
Choosing colors that stay readable and accessible
This chapter assumes you can already write a color measure with SWITCH ( TRUE (), ... ) and apply it through Format by field value. Here you change which colors that measure returns, and you add a second signal so color is never the only carrier of meaning.
Why red and green fail
About 1 in 12 men and 1 in 200 women have some form of color vision deficiency. The most common form makes red and green hard to tell apart. The #2E7D32 and #C62828 pair from the earlier variance measure can look almost identical to these viewers.
Contrast is a second problem. A cell with a colored background needs a font color that stays readable on it. The Web Content Accessibility Guidelines (WCAG) ask for a contrast ratio of at least 4.5:1 for normal text. They ask for at least 3:1 for large text and for graphical objects such as chart bars.
Use a color-blind-safe palette
Blue, orange, and vermillion stay distinct under the common types of color blindness. These values come from the Okabe-Ito palette.
| Meaning | Hex | Text color that stays readable |
|---|---|---|
| At or above 5% over target | `#0072B2` | White (about 5:1) |
| On target | `#E69F00` | Black (about 9:1) |
| Below target | `#D55E00` | Black (about 5:1) |
White text on #D55E00 only reaches about 3.9:1, which fails for normal text. That is why the table picks black for the last two rows.
Return both a background and a font color
Power BI lets you set the background color and the font color separately, and each can use its own measure. Write two measures that share the same thresholds.
Variance Color (Accessible) =
VAR v = [Variance %]
RETURN
SWITCH (
TRUE (),
ISBLANK ( v ), BLANK (),
v >= 0.05, "#0072B2",
v >= 0, "#E69F00",
"#D55E00"
)
Variance Font Color =
VAR v = [Variance %]
RETURN
SWITCH (
TRUE (),
ISBLANK ( v ), BLANK (),
v >= 0.05, "#FFFFFF",
"#000000"
)Apply the first measure under Cell elements > Background color and the second under Font color. In both dialogs, set Format style to Field value and pick the measure.
Add a second signal
Never let color be the only signal. Put a symbol or a word in the cell as well. A text measure is the cheapest way to do this.
Variance Status =
VAR v = [Variance %]
RETURN
SWITCH (
TRUE (),
ISBLANK ( v ), BLANK (),
v >= 0.05, "▲ Above target",
v >= 0, "● On target",
"▼ Below target"
)The shapes differ, so a reader sees the status even in grayscale or on a printout. You can also use the SVG icon technique from the previous chapter, as long as the icons differ in shape and not only in color.
Common mistakes
- Reusing one font color. A white font on an amber background is hard to read, so match the font color to each background.
- Too many colors. Three or four states are enough. More states force readers to memorize a legend.
- Relying on theme colors. A measure returns a fixed hex string, so it ignores the report theme. If you switch to a dark theme, check the contrast again.
- Unexplained colors. Add a short legend or a note in the visual title so the thresholds are visible, for example "Blue: 5% or more above target".
Exercise
Your matrix uses #F9A825 (amber) as a background for on-target cells, and the font color is white. Name the problem and the fix, using the measures in this chapter.
Show answer
White text on amber has low contrast, well below 4.5:1. Add a separate font color measure, such as Variance Font Color, that returns black on amber and white on dark blue. Apply it under Font color with Format style set to Field value. Also add a symbol or status text so the state does not depend on color alone.