Sub topic 12
Choosing colors that stay readable and accessible
A measure that returns a color gives you full control over what a cell looks like. It also makes you responsible for whether people can read it. This chapter covers three problems: users who cannot tell your colors apart, text that disappears against a colored fill, and meaning that exists only as color. It assumes you can write a measure such as [Variance %] and apply a measure through Format by field value, as covered in the earlier chapters.
Why accessibility matters here
The built-in rules and gradient options use palettes that Power BI offers, though you can change them. When you write the hex string yourself, no tool checks it. Three failures are common:
- Color vision deficiency. About 8% of men and 0.5% of women have some form of red-green color deficiency. The classic green, amber and red traffic light is the worst palette for this group, and it is the one most dashboards use.
- Low contrast. Dark text on a dark fill, or white text on a yellow fill, is unreadable for everyone in bright light and for many users all the time.
- Color-only meaning. If a cell is "bad" only because it is red, that status is lost in a grayscale printout, a screenshot pasted into a document, or a screen reader.
The Web Content Accessibility Guidelines (WCAG) give measurable targets. Rule 1.4.1 says color must not be the only way to convey information. Rule 1.4.3 asks for a contrast ratio of at least 4.5:1 for normal text. Rule 1.4.11 asks for at least 3:1 for graphical objects such as chart bars and icons. A contrast ratio compares the relative luminance (perceived brightness) of two colors. It runs from 1:1 (identical) to 21:1 (black on white).
Pick a palette that survives color blindness
Blue and orange stay distinct for almost every type of color vision deficiency, because they differ along an axis that red-green deficiencies do not affect. The Okabe-Ito palette was designed for this purpose. The table below uses three of its colors for the good, near-target and bad states from earlier chapters.
| State | Hex | Contrast with white | Contrast with black | Text color to use |
|---|---|---|---|---|
| Good (at or above 5%) | `#0072B2` | about 5.2:1 | about 4.0:1 | White |
| Near target (0 to 5%) | `#E69F00` | about 2.2:1 | about 9.3:1 | Black |
| Bad (below target) | `#D55E00` | about 3.9:1 | about 5.4:1 | Black |
Compare these with the traffic-light palette used in the first example of this tutorial. Amber #F9A825 gives only about 2:1 against white but about 10.6:1 against black. Green #2E7D32 and red #C62828 both give above 5:1 against white. Those contrast numbers are fine. The problem with that palette is that green and red look alike to many viewers, so you should add a second signal, described below.
The values above are approximate. Check your own colors with a contrast checker before you ship, and test the final result with a color vision simulator such as Color Oracle or Coblis.
Keep the palette in one place
A hex string typed into five measures is five places to fix when a stakeholder asks for different colors. Define each color once as a measure and reference it everywhere.
Color Good = "#0072B2"
Color Neutral = "#E69F00"
Color Bad = "#D55E00"
Variance Color (Accessible) =
VAR v = [Variance %]
RETURN
SWITCH (
TRUE (),
ISBLANK ( v ), BLANK (),
v >= 0.05, [Color Good],
v >= 0, [Color Neutral],
[Color Bad]
)This measure behaves exactly like [Variance Color] from the earlier chapter. It still returns a blank for missing data, so those cells keep no color. Only the strings changed.
Power BI themes also define "good", "neutral" and "bad" sentiment colors, and the built-in rules and gradient dialogs offer them. A DAX measure cannot read the active theme, so a measure-driven color is a separate copy of your palette. If you change the theme, update the three color measures too.
Set the font color as well as the fill
When you color a cell background, Power BI leaves the font color alone. A white font on the amber or orange fill above would be hard to read, and a black font on the blue fill would be weak. The fix is a second measure that picks the text color to match the fill, applied through Format by field value on the Font color setting.
Variance Font Color =
VAR bg = [Variance Color (Accessible)]
RETURN
SWITCH (
bg,
[Color Good], "#FFFFFF",
[Color Neutral], "#000000",
[Color Bad], "#000000",
BLANK ()
)Because this measure reads the fill measure and compares it with the palette measures, the two cannot drift apart. Change [Color Good] to a lighter blue and the comparison still matches. You still have to re-check the contrast of the new pairing yourself. A blank fill produces a blank font color, so Power BI uses the visual's normal text color.
To apply both measures to a table or matrix:
- Select the visual and open the Format pane.
- Under Cell elements, turn on Background color and choose the fx button.
- Set Format style to Field value and pick
Variance Color (Accessible)in the field box. - Repeat for Font color, picking
Variance Font Color.
Never let color carry the meaning alone
Choosing a good palette reduces the problem, but it does not remove it. Add a second channel that does not depend on hue. The cheapest option is a text label with a symbol, which shows up in screenshots, grayscale prints and screen readers.
Variance Label =
VAR v = [Variance %]
RETURN
SWITCH (
TRUE (),
ISBLANK ( v ), BLANK (),
v >= 0.05, "▲ " & FORMAT ( v, "+0.0%;-0.0%;0.0%" ),
v >= 0, "● " & FORMAT ( v, "+0.0%;-0.0%;0.0%" ),
"▼ " & FORMAT ( v, "+0.0%;-0.0%;0.0%" )
)Use this measure as the displayed value, and keep the color measures for the formatting. A reader who cannot see the fill still sees an upward triangle, a dot or a downward triangle next to the number. Note that FORMAT returns text, so the cell can no longer be sorted numerically by this column. Keep the numeric [Variance %] for sorting, either in a hidden column of the table or as a tooltip field.
The SVG status icon from the previous chapter is another second channel, as long as the shapes differ. A green circle and a red circle are the same shape, so a color-blind reader gets nothing from them. Use a circle, a triangle and a square, or a check mark and a cross.
The flow below shows how one value produces several signals.
Gradients and diverging scales
The same reasoning applies to the gradient style. A red-to-green diverging gradient fails for the same reason as the traffic light, and it also has a middle that turns muddy brown. Better choices:
- Use a blue-to-orange diverging scale when the data has a meaningful midpoint such as a target.
- Use a single-hue scale that runs from light to dark when you only show "more" or "less". Lightness differences stay visible under every type of color vision.
- Make sure the lightest end is still visible against the page. A pale yellow cell on a white page can fall below the 3:1 graphics ratio even though it is technically colored.
If you write gradient colors in DAX, return the interpolated hex string from a measure. Keep both end colors in palette measures like the ones above.
Chart elements and backgrounds
For charts, the contrast target is 3:1 between each colored element and the background, and also between neighboring elements. Two bars with similar blues next to each other may both pass against white and still be impossible to tell apart. Where several series are colored by a measure, add data labels or direct labels so the reader does not need a legend lookup.
Also check your colors on each background where the report will appear. A palette tested on white can fail on a dark theme or on a colored page. If the report might be viewed both ways, test both.
A short checklist
- Fill and font colors both set, and the contrast of every pair checked.
- No red-green pairs as the only distinction.
- A symbol, label or icon shape that matches each color state.
- Blank values show no color, as before, rather than a "bad" color.
- The palette lives in measures, so one edit changes every visual.
- A simulator view and a grayscale view of the finished page both still make sense.
Exercise
A matrix uses Variance Color with amber #F9A825 for "near target" cells, and the font color is left at white. Users report that the amber cells are hard to read. What is wrong, and how do you fix it with measures?
Show answer
White text on amber has a contrast ratio of only about 2:1, well below the 4.5:1 that WCAG asks for. Black text on the same amber is about 10.6:1. Add a font color measure that reads the fill measure and returns "#000000" when the fill is amber and "#FFFFFF" for the dark green and red fills, then apply it to Font color with Format by field value. For users who cannot tell the three fills apart, also show a label measure with a different symbol for each state.