Sub topic 3
Controlling Measure-Driven Conditional Formatting
Assume you can build Power BI matrix and chart visuals, write basic DAX measures, and use the Format pane. This chapter focuses on controlling where formatting appears and testing the measure behind it.
Controlling totals, subtotals, and matrix levels
A matrix evaluates a measure at every row level, including categories, subcategories, subtotals, and the grand total. A color that makes sense for a product row may mislead users when applied to an aggregate.
ISINSCOPE checks whether the current cell belongs to a specific grouping level. Return a color only at the level you want to format.
Variance Color (Matrix) =
IF (
ISINSCOPE ( Product[Category] ),
[Variance Color],
BLANK ()
)This measure applies the existing color logic to category rows. Subcategories, subtotals, and the grand total return blank, so they receive no conditional color.
Letting users set thresholds with a parameter table
A disconnected parameter table can provide threshold choices without changing your model relationships.
Threshold = GENERATESERIES ( 0, 0.2, 0.01 )
Green Threshold =
SELECTEDVALUE ( Threshold[Value], 0.05 )Add Threshold[Value] to a slicer. Then use [Green Threshold] inside the color measure. The default is 5% when the user selects nothing or selects multiple values.
Using formatting on charts and titles
Measure-driven formatting can control chart series colors, data labels, and some title or background properties. In the visual's formatting card, choose fx, select Format by: Field value, and select the color measure. The visual must support field-value formatting for that property.
Drawing status icons with SVG measures
A measure can return an SVG data URI. Set its data category to Image URL, then add it to a table or matrix.
Status Icon =
VAR v = [Variance %]
VAR fill = IF ( v >= 0, "%2327AE60", "%23C0392B" )
RETURN
IF (
ISBLANK ( v ),
BLANK (),
"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16'><circle cx='8' cy='8' r='7' fill='" & fill & "'/></svg>"
)Choosing readable and accessible colors
Do not communicate status with color alone. Add an icon, label, or variance value. Use strong contrast, distinguishable colors, and a legend. Test the report with grayscale or color-vision simulation.
Testing and troubleshooting
Create a temporary table with the grouping field, [Variance %], and the color measure. Inspect whether the measure returns the expected hex string or blank. If formatting does not appear, check that:
- The measure returns valid color names or hex values.
- Format by is set to Field value.
- The measure is selected in the correct formatting property.
- The visual supports that property.
- The field has the correct data category when using SVG.
ISINSCOPEmatches the actual matrix field and level.
Exercise
Why might a matrix total remain uncolored when category rows are colored?
Show answer
The color measure returns BLANK() because ISINSCOPE ( Product[Category] ) is false at the total level.