agentleFS
wardawgmalviciouswardawgmalvicious/agent-config/skills/powerbi/pbir-conditional-formatting/SKILL.md

pbir-conditional-formatting

Skill1 starsChanged 56 days agoMITView on GitHub

Use when adding conditional formatting to a Power BI visual — per-point bar/column colors, diverging gradients, line segment colors, marker transparency, data bars, conditional icons. Three approaches — measure-based (extension measure dataType Text returning theme tokens good/bad/neutral/minColor/midColor/maxColor), FillRule linearGradient2/linearGradient3, rule-based Conditional.Cases. Plus dataViewWildcard selector with matchingOption 1 for per-point, required two-entry array pattern for dataPoint/lineStyles/error, extension measures attaching to EXISTING semantic-model entities via reportExtensions.json, Schema extension on report-level measures, line segment limits (single-series only, segmentGradient affects strokeColor only), marker color/shape/size NOT CF-able (use transparency), ComparisonKind codes 0-4, ScopedEval + AllRolesRef for global min/max.

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Not every property accepts measure expressions.

    line 27

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

PBIR Conditional Formatting Reference

Three approaches: measure-based (flexible), FillRule gradients (no DAX), and rule-based Conditional (UI-generated).

Approach Matrix

ApproachBest ForProsCons
Measure-basedCustom logic, theme colorsFull DAX, readableRequires extension measure
linearGradient2 / linearGradient3Color scalesNo DAXGradients only
Conditional.CasesUI-portable rulesPower BI UI round-tripsVerbose

Supported Properties

Not every property accepts measure expressions. These do:

fill, borderColor, defaultColor, fontColor, color, backgroundColor, lineColor, markerColor, strokeColor, text, titleText, fontSize, strokeWidth, weight, transparency, radius, url, good, bad, neutral, target, icon

Everything else is literal-only or ThemeDataColor.

dataViewWildcard Selector

The key to per-point formatting.

matchingOptionBehavior
0Identities + totals (series-level)
1Per data point (most common for CF)
2Totals only
"selector": {"data": [{"dataViewWildcard": {"matchingOption": 1}}]}

Wrong for per-point: "selector": {"metadata": "Sales.Revenue"} — evaluates once per series.

Two-Entry Array Pattern (Required)

dataPoint, lineStyles, error require a two-entry array: base entry + conditional entry.

"dataPoint": [
  {"properties": {}},
  {
    "properties": {
      "fill": {"solid": {"color": {"expr": {"Measure": {
        "Expression": {"SourceRef": {"Schema": "extension", "Entity": "_Formatting"}},
        "Property": "Bar Color"
      }}}}}
    },
    "selector": {"data": [{"dataViewWildcard": {"matchingOption": 1}}]}
  }
]

Extension Measure (for color CF)

Defined in Report.Report/definition/reportExtensions.json. dataType MUST be "Text" for color measures. Must attach to an EXISTING entity from the model.

{
  "name": "extension",
  "entities": [{
    "name": "_Formatting",
    "measures": [{
      "name": "Bar Color",
      "dataType": "Text",
      "expression": "SWITCH(TRUE(), [Value]<10, \"bad\", [Value]<50, \"neutral\", \"good\")"
    }]
  }]
}

Theme color names returned by measures: "bad", "good", "neutral", "minColor", "midColor", "maxColor".

Measure Reference in CF Expressions

{"expr": {"Measure": {
  "Expression": {"SourceRef": {"Schema": "extension", "Entity": "_Formatting"}},
  "Property": "Bar Color"
}}}

"Schema": "extension" is required for report-level extension measures. Omit for model measures.

Pattern — Bar / Column Fill

"dataPoint": [
  {"properties": {}},
  {
    "properties": {
      "fill": {"solid": {"color": {"expr": {"Measure": {
        "Expression": {"SourceRef": {"Schema": "extension", "Entity": "_Formatting"}},
        "Property": "Bar Color"
      }}}}}
    },
    "selector": {"data": [{"dataViewWildcard": {"matchingOption": 1}}]}
  }
]

Pattern — linearGradient2 (Two-Color)

Data-driven (scale to observed range):

{"FillRule": {"linearGradient2": {
  "min": {"color": {"Literal": {"Value": "'minColor'"}}},
  "max": {"color": {"Literal": {"Value": "'maxColor'"}}},
  "nullColoringStrategy": {"strategy": {"Literal": {"Value": "'asZero'"}}}
}}}

Explicit bounds (fixed thresholds):

{"FillRule": {"linearGradient2": {
  "min": {"color": {"Literal": {"Value": "'minColor'"}}, "value": {"Literal": {"Value": "0D"}}},
  "max": {"color": {"Literal": {"Value": "'maxColor'"}}, "value": {"Literal": {"Value": "1D"}}},
  "nullColoringStrategy": {"strategy": {"Literal": {"Value": "'asZero'"}}, "color": {"Literal": {"Value": "'#FFFFFF'"}}}
}}}

Pattern — linearGradient3 (Diverging)

{"FillRule": {"linearGradient3": {
  "min": {"color": {"Literal": {"Value": "'minColor'"}}, "value": {"Literal": {"Value": "-1D"}}},
  "mid": {"color": {"Literal": {"Value": "'neutral'"}}, "value": {"Literal": {"Value": "0D"}}},
  "max": {"color": {"Literal": {"Value": "'maxColor'"}}, "value": {"Literal": {"Value": "1D"}}},
  "nullColoringStrategy": {"strategy": {"Literal": {"Value": "'asZero'"}}}
}}}

Pattern — Line Segment Colors (Single-Series Only)

Multi-series line charts cannot use segment coloring. Measure must return hex.

"lineStyles": [
  {"properties": {"segmentGradient": {"expr": {"Literal": {"Value": "true"}}}}},
  {
    "properties": {
      "strokeColor": {"solid": {"color": {"expr": {"Measure": {
        "Expression": {"SourceRef": {"Schema": "extension", "Entity": "_Formatting"}},
        "Property": "Line Color"
      }}}}}
    },
    "selector": {"data": [{"dataViewWildcard": {"matchingOption": 1}}]}
  }
]

segmentGradient only affects strokeColor. It does NOT work with lineStyle, strokeWidth, or markerFill.

Pattern — Axis Label Colors

No selector needed.

"categoryAxis": [{
  "properties": {
    "labelColor": {"solid": {"color": {"expr": {"Measure": {
      "Expression": {"SourceRef": {"Schema": "extension", "Entity": "_Formatting"}},
      "Property": "Axis Color"
    }}}}}
  }
}]

Pattern — Marker Transparency (0-100)

Marker color / shape / size do NOT support CF. Transparency does.

"markers": [
  {"properties": {"borderShow": {"expr": {"Literal": {"Value": "false"}}}}},
  {
    "properties": {
      "transparency": {"expr": {"Measure": {
        "Expression": {"SourceRef": {"Schema": "extension", "Entity": "_Measures"}},
        "Property": "Marker Opacity"
      }}}
    },
    "selector": {"data": [{"dataViewWildcard": {"matchingOption": 1}}]}
  }
]

Pattern — Rule-Based Conditional

{"expr": {"Conditional": {"Cases": [
  {"Condition": {...}, "Value": {"Literal": {"Value": "'#FF0000'"}}},
  {"Condition": {...}, "Value": {"Literal": {"Value": "'#00FF00'"}}}
]}}}

Cases evaluated in order; first match wins.

ComparisonKind Codes

ValueOperator
0Equal
1Greater than
2Greater than or equal
3Less than or equal
4Less than

Logical Wrappers

{"And": {"Left": {...}, "Right": {...}}}
{"Or":  {"Left": {...}, "Right": {...}}}
{"Not": {"Expression": {...}}}

ScopedEval + AllRolesRef (Global Context)

Removes filter context for global min/max:

{"ScopedEval": {"Expression": {"Measure": {...}}, "Scope": [{"AllRolesRef": {}}]}}

Data Bars (table/matrix columns)

"dataBars": {
  "positiveColor": {"solid": {"color": {"expr": {"Literal": {"Value": "'#E1EBF2'"}}}}},
  "negativeColor": {"solid": {"color": {"expr": {"Literal": {"Value": "'#E5B97D'"}}}}},
  "axisColor":     {"solid": {"color": {"expr": {"Literal": {"Value": "'#FFFFFF'"}}}}},
  "reverseDirection": {"expr": {"Literal": {"Value": "false"}}},
  "hideText":         {"expr": {"Literal": {"Value": "false"}}}
}

Conditional Icons

"icon": {
  "kind": "Icon",
  "layout": {"expr": {"Literal": {"Value": "'IconOnly'"}}},
  "value": {"expr": {"Conditional": {"Cases": [
    {"Condition": {"Comparison": {"ComparisonKind": 4, "Left": {"Measure": {...}}, "Right": {"Literal": {"Value": "0D"}}}},
     "Value": {"Literal": {"Value": "'SymbolMedium'"}}}
  ]}}}
}

Custom icon from a URL

The block above is the Rules format style, driving a built-in icon set. The other style, Field value, points at a column of image URLs and renders those instead of a built-in icon — the way to get an arbitrary custom icon into a table or matrix cell.

  • The URL may be an anonymously accessible web URL, or a OneLake file URL: https://onelake.dfs.fabric.microsoft.com/{workspace-id}/{item-id}/Files/{path-to-image}
  • Icons must be BMP, JPG, JPEG, GIF, PNG or SVG.
  • Desktop path: field dropdown → Conditional formatting → Icons → Format style = Field value. Icon layout still controls left / right of the value or icon-only.

Two limits ride along when the URL is a OneLake one — Power BI loads it under each viewer's Entra identity, so:

  • Viewers need Read on the lakehouse item and OneLake Read on the folder holding the image. Access to the report does not grant it.
  • Publish to web and anonymous embed cannot use OneLake URLs at all — they have no identity to authenticate with. Use an anonymously accessible web URL for reports headed there. See powerbi-report-authoring/references/image.md for the full OneLake image-source model.

The visual.json encoding for the Field value icon source is deliberately not given here — it was not observed against a real PBIP export, and this skill's property paths are only worth having when they are verified. The block above is the Rules style and does not carry over unchanged.

Gotchas

IssueCauseFix
All points get same colormetadata selector usedSwitch to dataViewWildcard with matchingOption: 1
CF works intermittentlySingle-entry array with selectorUse two-entry array pattern
Measure rejected as colordataType not "Text" in reportExtensions.jsonSet "dataType": "Text"
Extension measure not foundCreated new entity in reportExtensions.jsonEntities must already exist in the semantic model
Line segment colors don't workChart has multiple series in Y/Y2Segment coloring requires a single series
Marker color CF ignoredMarker fill/shape/size don't support CFUse transparency instead
segmentGradient + strokeWidth silently failsOnly strokeColor is supportedDon't combine
reportExtensions.json deserialization failsEmpty entities: []Delete the file entirely when no extension measures exist
title / legend selector ignoredThese objects don't accept selectorsApply globally (no selector)
Gradient midpoint shifts unexpectedlyData-driven bounds when fixed neededSwitch to explicit bounds form with value on min/mid/max
AllRolesRef scope wrong placeNested incorrectlyScopedEval.Scope: [{"AllRolesRef": {}}] at the outer wrapper
URL-sourced custom icons vanish in Publish to webThe column holds OneLake URLs, which cannot authenticate anonymouslyUse anonymously accessible web URLs for any report published to web or anonymously embedded

Reference

See also

  • pbir-visual-json — selectors, expressions, literal suffixes
  • pbir-themes — ThemeDataColor and theme token resolution

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.