SVG Visuals via DAX Measures (PBIR)
Report modification requires tooling. Two paths exist:
pbir CLI (preferred) -- use the pbir command and the pbir-cli skill. Install with uv tool install pbir-cli or pip install pbir-cli on macOS or Windows; neither works on Linux, where path 2 is the only option. Check availability with pbir --version.
- Direct JSON modification -- if
pbir is not available, use the pbir-format skill (pbip plugin) for PBIR JSON structure and patterns. Validate every change with jq empty <file.json>.
If neither the pbir-cli skill nor the pbir-format skill is loaded, ask the user to install the appropriate plugin before proceeding with report modifications.
Generate inline SVG graphics using DAX measures that return SVG markup strings. These render as images in table, matrix, card, image, and slicer visuals. Store as extension measures in reportExtensions.json.
How It Works
- A DAX measure returns an SVG string prefixed with
data:image/svg+xml;utf8,
- The measure's
dataCategory is set to ImageUrl
- Power BI renders the SVG as an image in supported visuals
Three constraints to check before you start
Publish to web forbids report level measures. The default advice above is to store these as
extension measures in reportExtensions.json. If the report will ever be shared with Publish to
web, that choice blocks it outright: report level DAX measures are on the Microsoft Learn
unsupported list
(https://learn.microsoft.com/power-bi/collaborate-share/service-publish-to-web#considerations-and-limitations).
Put the measures in the semantic model instead and leave reportExtensions.json empty. The report
and its model must also sit in the same workspace.
Deneb will not accept the ;utf8, prefix. Feeding one of these measures into a Deneb image mark
is a different code path from a table cell. Deneb's certified build ships a custom Vega loader whose
data URI regex accepts ;charset=utf-8,, a bare comma, and ;base64,, but rejects ;utf8,,
substituting a blank PNG plus a header warning icon rather than raising an error. Every example in
this skill uses ;utf8,, which is correct for native visuals and silently wrong inside Deneb. If one
measure feeds both, emit ;charset=utf-8,. Established by extracting the regex from Deneb's
loader.ts and testing it against eleven URI forms; not yet reproduced inside Deneb in product,
so confirm before relying on it.
Power Query silently truncates at 32,766 characters. That is a different and lower limit than the
DAX engine's, which raises an error near 2.1 million characters rather than truncating. It matters
when an image is stored in the model rather than generated: a base64 payload is capped at roughly
24 KB of source image.
Supported Visuals
- Table (
tableEx): grid.imageHeight / grid.imageWidth -- references/svg-table-matrix.md
- Matrix (
pivotTable): same as table -- references/svg-table-matrix.md
- Image (
image): sourceType='imageData' + sourceField -- references/svg-image-visual.md
- Card/New (
cardVisual): callout.imageFX -- references/svg-card-slicer.md
- Slicer/New (
advancedSlicerVisual): header images -- references/svg-card-slicer.md
Workflow: Creating an SVG Measure
Step 0: Design and Preview
Before writing DAX, design the SVG visually:
- Query the model first -- use DAX Studio or Tabular Editor CLI to get actual values with the intended filter context. Use real numbers, not placeholders.
- Write static SVG to a temp file -- save to
/tmp/mockup.svg and open it in a browser to preview layout, colors, and proportions.
- Ask for feedback before converting to DAX -- iterating on static SVG is far easier than on DAX string concatenation.
- Colors must be hex codes with
# -- e.g., fill='#2B7A78'. Never use %23 URL encoding or named colors. Always hex.
Step 1: Create the Extension Measure
Create the extension measure in reportExtensions.json manually (see the pbir-format skill in the pbip plugin for JSON structure).
# Example using pbir_object_model (if available):
report.add_extension_measure(
table="Orders",
name="Sparkline SVG",
expression='''
VAR _Prefix = "data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 30'>"
VAR _Bar = "<rect x='0' y='0' width='50' height='30' fill='#2196F3'/>"
VAR _Suffix = "</svg>"
RETURN _Prefix & _Bar & _Suffix
''',
data_type="Text",
data_category="ImageUrl",
display_folder="SVG Charts",
)
report.save()
Step 1b: Review
Before presenting the measure to the user, dispatch the svg-reviewer agent to validate syntax and provide design feedback.
Step 2: Bind to a Visual
Extension measures use "Schema": "extension" in the SourceRef:
{
"field": {
"Measure": {
"Expression": {
"SourceRef": {"Schema": "extension", "Entity": "Orders"}
},
"Property": "Sparkline SVG"
}
}
}
For image visuals, set sourceType='imageData' with sourceField in the visual.json (see references/svg-image-visual.md).
Step 3: Validate
Validate JSON syntax with jq empty <reportExtensions.json> and inspect the file to confirm measure definitions and data categories.
Prefer UDF Libraries Over Custom DAX
Before writing a custom SVG measure from scratch, check whether an existing UDF library already provides the chart type:
- PowerofBI.IBCS (Andrzej Leszkiewicz) -- IBCS-compliant bar, column, waterfall, pin, small multiples, and P&L charts. Preferred for business reporting with AC/PY/BU/FC comparisons. Install from https://daxlib.org/package/PowerofBI.IBCS/
- DaxLib.SVG (Jake Duddy) -- general-purpose sparklines, bars, boxplots, heatmaps, jitter, violin, progress bars, pills. Install from https://daxlib.org/package/DaxLib.SVG/ -- source at https://github.com/daxlib/dev-daxlib-svg
- PowerBI MacGuyver Toolbox (Stepan Resl / Data Goblins) -- C# scripts that generate SVG measures via Tabular Editor
To check if a library is installed, look for functions/measures starting with PowerofBI.IBCS., Viz., Compound., or Element.. Only write custom SVG DAX when no library function covers the required visualization. See references/community-examples.md for full function listings and additional libraries.
Installing UDF libraries
UDF libraries are installed into the semantic model, not the report. Use one of these tools:
- Tabular Editor CLI (
te command) -- use the te-docs skill for guidance
- Power BI MCP server -- if available, use it to modify the model directly
connect-pbid skill -- connect to Power BI Desktop's local Analysis Services instance via TOM/PowerShell
tmdl skill -- edit TMDL files directly in a PBIP project (last resort)
DAX SVG Conventions
Measure Structure (VAR Pattern)
Every SVG measure must follow a strict VAR-based structure. Organize code into clearly separated regions:
SVG Measure =
-- CONFIG: Input fields and visual parameters
VAR _Actual = [Sales Amount]
VAR _Target = [Sales Target]
VAR _Scope = ALLSELECTED ( 'Product'[Category] )
-- CONFIG: Colors
VAR _BarColor = "#5B8DBE"
VAR _TargetColor = "#333333"
-- NORMALIZATION: Scale values to SVG coordinate space
VAR _AxisMax = CALCULATE( MAXX( _Scope, [Sales Amount] ), REMOVEFILTERS( 'Product'[Category] ) ) * 1.1
VAR _AxisRange = 100
VAR _ActualNormalized = DIVIDE( _Actual, _AxisMax ) * _AxisRange
-- SVG ELEMENTS: One VAR per visual element
VAR _SvgPrefix = "data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 25'>"
VAR _Sort = "<desc>" & FORMAT( _Actual, "000000000000" ) & "</desc>"
VAR _Bar = "<rect x='0' y='5' width='" & _ActualNormalized & "' height='15' fill='" & _BarColor & "'/>"
VAR _TargetLine = "<rect x='" & DIVIDE( _Target, _AxisMax ) * _AxisRange & "' y='2' width='2' height='21' fill='" & _TargetColor & "'/>"
VAR _SvgSuffix = "</svg>"
-- ASSEMBLY: Combine in rendering order (back to front)
VAR _SVG = _SvgPrefix & _Sort & _Bar & _TargetLine & _SvgSuffix
RETURN _SVG
Key conventions:
- CONFIG section first -- input measures, scope column, colors, font settings. Users change only this section.
- NORMALIZATION section -- scale raw values to SVG coordinate space (see below)
- SVG ELEMENTS -- one VAR per
<rect>, <circle>, <text>, <line>, etc.
- ASSEMBLY -- concatenate elements in document order (first = back layer, last = front)
<desc> sort trick -- embed FORMAT(_Actual, "000000000000") in a <desc> tag so the table/matrix can sort by the SVG column
Axis Normalization (Critical)
SVG coordinates must be normalized to a fixed range. Raw measure values (e.g., 1,234,567) cannot be used directly as pixel coordinates. The standard pattern:
-- 1. Define the SVG coordinate range
VAR _BarMin = 0 -- leftmost position (or offset for labels)
VAR _BarMax = 100 -- rightmost position
-- 2. Find the maximum value across all rows in the visual's filter context
VAR _Scope = ALLSELECTED( 'Table'[GroupColumn] )
VAR _MaxInScope = CALCULATE( MAXX( _Scope, [Measure] ), REMOVEFILTERS( 'Table'[GroupColumn] ) )
VAR _AxisMax = _MaxInScope * 1.1 -- 10% padding
-- 3. Normalize each value to the SVG range
VAR _AxisRange = _BarMax - _BarMin
VAR _Normalized = DIVIDE( _Actual, _AxisMax ) * _AxisRange
Use ALLSELECTED for the scope when the chart should respond to slicer context. Use ALL for a fixed axis across all filter contexts. The * 1.1 padding prevents bars from touching the edge.
HASONEVALUE Guard
Table/matrix SVG measures must guard against subtotal/total rows where multiple categories are in scope:
IF( HASONEVALUE( 'Table'[GroupColumn] ),
-- SVG code here
)
Without this guard, the measure evaluates on grand total rows with meaningless aggregated values.
Escaping and Color Rules
- Single quotes for SVG attributes -- avoids DAX double-quote escaping:
fill='#2196F3'
- Double quotes in DAX: escape as
"" (DAX convention)
viewBox for responsive scaling: viewBox='0 0 100 25'
xmlns required on <svg> element
- Hex colors with
# only -- e.g., fill='#2196F3'. %23 URL encoding causes errors in image visuals. Never use named colors.
- No JavaScript -- SVG must be purely declarative
SVG Coordinate System
- Y=0 is at the top -- invert values for charts:
_Height - _Value
- Use
viewBox with a 0-100 range for normalized coordinates
- Elements render in document order (first = back, last = front)
CONCATENATEX for Series Data
For sparklines and multi-point charts, build coordinate strings with CONCATENATEX:
VAR _Points = CONCATENATEX(
_SparklineTable,
[X] & "," & (100 - [Y]),
" ",
[Date], ASC
)
-- Produces: "0,80 10,60 20,40 30,20"
-- Use in: <polyline points='...'/>
Best Practices
- Check UDF libraries first -- use DaxLib.SVG or MacGuyver Toolbox functions before writing custom DAX
- VAR pattern mandatory -- one VAR per config value, one VAR per SVG element, assembly at the end
- Normalize all values -- raw measure values must be scaled to SVG coordinate range
- HASONEVALUE guard -- always guard against total/subtotal rows in table/matrix context; use
ISINSCOPE for nested hierarchy levels
<desc> sort trick -- embed formatted value in <desc> for sortable SVG columns
- Use
viewBox for responsive scaling instead of fixed width/height
- Round coordinates to integers for performance (shorter strings, cheaper FORMAT calls)
- Store as extension measures -- SVG measures don't belong in the semantic model
- Use
display_folder to organize SVG measures (e.g., "SVG Charts")
- Preview first -- save static SVG to
/tmp/, open in browser, iterate before writing DAX
- 32K character limit on the rendered SVG string per cell (not the DAX expression); see
references/svg-table-matrix.md for diagnosis and mitigation
- Pre-aggregate in model measures -- let the storage engine cache aggregations; the SVG measure maps numbers to coordinates only
- Hex colors only --
# directly, never %23 URL encoding
- Image visuals need no
query block -- only objects.image with sourceType='imageData' and sourceField
- Accessibility: every SVG encoding primary data needs adjacent readable columns and a dynamic alt-text measure; see
references/svg-accessibility.md
reportExtensions.json Format
{
"$schema": "https://developer.microsoft.com/json-schemas/fabric/item/report/definition/reportExtension/1.0.0/schema.json",
"name": "extension",
"entities": [{
"name": "ExistingTable",
"measures": [{
"name": "Sparkline SVG",
"dataType": "Text",
"dataCategory": "ImageUrl",
"expression": "...",
"displayFolder": "SVG Charts"
}]
}]
}
Limitations
- No interactivity -- SVG images are static (no hover, click, tooltip)
- No JavaScript -- inline scripts are stripped
- 32K character limit per rendered cell string (not the DAX expression);
CONCATENATEX over 30+ series points easily approaches this; prefer <polyline> over individual shapes, integer coordinates, and pre-aggregated series; see references/svg-table-matrix.md for full diagnosis
- Per-cell formula-engine cost -- each visible cell evaluates the string-building expression; push aggregations into model measures so SVG assembly is coordinate-mapping only
- Accessibility gap -- screen readers receive no per-cell data from an SVG URI; mitigate with adjacent readable columns and dynamic alt text; see
references/svg-accessibility.md
- Classic card (
card) does NOT support SVG -- use cardVisual instead
When to Use SVG Measures
SVG measures are the preferred choice for simple inline graphics embedded in tables, matrices, cards, and image visuals. Use SVG when you need:
- Sparklines, data bars, progress bars, or status indicators inside table/matrix cells
- KPI micro-charts in card visuals
- Lightweight visuals that don't require interactivity or complex data transforms
- No additional custom visual registration (works with native visuals)
Use Deneb instead for complex, interactive visualizations (cross-filtering, tooltips, hover states) or chart types that require extensive data transforms. Use Python/R instead for statistical analysis charts (distributions, regressions, correlations).
References
Community Examples and Libraries
references/community-examples.md -- Community SVG templates organized by target visual type (Table/Matrix, Image, Card), including DaxLib.SVG functions, Kerry Kolosko templates, and PowerBI MacGuyver Toolbox patterns
By Visual Type
references/svg-table-matrix.md -- Patterns for Table/Matrix: data bar, bullet chart, dumbbell, overlapping bars, lollipop, status pill, sparkline, bar sparkline, area sparkline, UDF patterns; axis normalization, sort trick, image size configuration, and per-cell performance guidance
references/svg-image-visual.md -- Patterns for Image visuals: KPI header, sparkline with endpoint, dashboard tile; sourceType binding, dynamic/conditional layout, responsive width guidance
references/svg-card-slicer.md -- Patterns for Card/Slicer: arrow indicator, mini gauge, mini donut, progress bar, narrative sentence; card binding via callout.imageFX
Accessibility
references/svg-accessibility.md -- Accessibility for SVG measures: adjacent readable columns, dynamic alt text, color-only encoding, contrast requirements, and severity guidance for audit findings
General
references/svg-elements.md -- SVG element reference (rect, circle, line, polyline, text, path, gradient, group)
Examples
Ready-to-use DAX measure expressions in examples/:
sparkline-measure.dax -- Line sparkline (polyline + CONCATENATEX)
progress-bar-measure.dax -- Conditional progress bar
dumbbell-chart-measure.dax -- Actual vs target dumbbell
bullet-chart-measure.dax -- Bullet chart with sentiment action dots
overlapping-bars-measure.dax -- Overlapping bars with variance label
boxplot-measure.dax -- Box-and-whisker plot (inspired by DaxLib.SVG)
ibcs-bar-measure.dax -- IBCS-compliant horizontal bar (inspired by avatorl)
jitter-plot-measure.dax -- Dot strip chart with jitter (inspired by DaxLib.SVG)
overlapping-bars-with-variance-measure.dax -- Overlapping bars with variance bar + arrow icon + % label (Kurt Buhler / Data Goblins)
lollipop-conditional-measure.dax -- Lollipop with scaled dot + auto-formatted label (Kurt Buhler / Data Goblins)
waterfall-measure.dax -- Waterfall with cumulative OFFSET positioning + connector lines (Kurt Buhler / Data Goblins)
status-pill-measure.dax -- Rounded pill badge with category color + text label (Kurt Buhler / Data Goblins)
Helper Libraries
| Library |
Author |
Key Features |
| DaxLib.SVG |
Jake Duddy |
UDF library: area, line, boxplot, heatmap, jitter, violin |
| PBI-Core-Visuals-SVG-HTML |
David Bacci |
Chips, tornado, gradient matrix, bar UDF |
| PowerBI MacGuyver Toolbox |
Stepan Resl / Data Goblins |
20+ bar, 14+ line, 24+ KPI templates |
| Dashboard Design UDF Library |
Dashboard-Design |
Target line bars, pill visuals |
| Kerry Kolosko Templates |
Kerry Kolosko |
Sparklines, data bars, KPI cards |
Related Skills
pbi-report-design -- Layout and design best practices
deneb-visuals -- Vega/Vega-Lite for complex interactive visualizations
python-visuals -- matplotlib/seaborn for statistical charts
r-visuals -- ggplot2 for statistical charts
pbir-format (pbip plugin) -- PBIR JSON format reference (extension measures, ImageUrl binding)
1---2name: svg-visuals3description: SVG generation via DAX measures and extension measures with ImageUrl data category for inline visualizations in PBIR reports. Automatically invoke when the user mentions "SVG visual", "DAX sparkline", "SVG measure", "inline graphics with DAX", "ImageUrl data category", "extension measure", or asks to create any DAX-generated chart (progress bars, bullet charts, KPI indicators, data bars, gauges, donut charts, lollipop charts, dumbbell charts, status pills, overlapping bars, boxplots, IBCS bars, jitter plots, box-and-whisker charts).4---56# SVG Visuals via DAX Measures (PBIR)78> **Report modification requires tooling.** Two paths exist:9> 1. **`pbir` CLI (preferred)** -- use the `pbir` command and the `pbir-cli` skill. Install with `uv tool install pbir-cli` or `pip install pbir-cli` on macOS or Windows; neither works on Linux, where path 2 is the only option. Check availability with `pbir --version`.10> 2. **Direct JSON modification** -- if `pbir` is not available, use the `pbir-format` skill (pbip plugin) for PBIR JSON structure and patterns. Validate every change with `jq empty <file.json>`.11>12> If neither the `pbir-cli` skill nor the `pbir-format` skill is loaded, ask the user to install the appropriate plugin before proceeding with report modifications.1314Generate inline SVG graphics using DAX measures that return SVG markup strings. These render as images in table, matrix, card, image, and slicer visuals. Store as extension measures in `reportExtensions.json`.1516## How It Works17181. A DAX measure returns an SVG string prefixed with `data:image/svg+xml;utf8,`192. The measure's `dataCategory` is set to `ImageUrl`203. Power BI renders the SVG as an image in supported visuals2122## Three constraints to check before you start2324**Publish to web forbids report level measures.** The default advice above is to store these as25extension measures in `reportExtensions.json`. If the report will ever be shared with **Publish to26web**, that choice blocks it outright: report level DAX measures are on the Microsoft Learn27unsupported list28(<https://learn.microsoft.com/power-bi/collaborate-share/service-publish-to-web#considerations-and-limitations>).29Put the measures in the semantic model instead and leave `reportExtensions.json` empty. The report30and its model must also sit in the same workspace.3132**Deneb will not accept the `;utf8,` prefix.** Feeding one of these measures into a Deneb image mark33is a different code path from a table cell. Deneb's certified build ships a custom Vega loader whose34data URI regex accepts `;charset=utf-8,`, a bare comma, and `;base64,`, but **rejects `;utf8,`**,35substituting a blank PNG plus a header warning icon rather than raising an error. Every example in36this skill uses `;utf8,`, which is correct for native visuals and silently wrong inside Deneb. If one37measure feeds both, emit `;charset=utf-8,`. Established by extracting the regex from Deneb's38`loader.ts` and testing it against eleven URI forms; **not yet reproduced inside Deneb in product**,39so confirm before relying on it.4041**Power Query silently truncates at 32,766 characters.** That is a different and lower limit than the42DAX engine's, which raises an error near 2.1 million characters rather than truncating. It matters43when an image is stored in the model rather than generated: a base64 payload is capped at roughly4424 KB of source image.4546## Supported Visuals4748- Table (`tableEx`): `grid.imageHeight` / `grid.imageWidth` -- `references/svg-table-matrix.md`49- Matrix (`pivotTable`): same as table -- `references/svg-table-matrix.md`50- Image (`image`): `sourceType='imageData'` + `sourceField` -- `references/svg-image-visual.md`51- Card/New (`cardVisual`): `callout.imageFX` -- `references/svg-card-slicer.md`52- Slicer/New (`advancedSlicerVisual`): header images -- `references/svg-card-slicer.md`5354## Workflow: Creating an SVG Measure5556### Step 0: Design and Preview5758Before writing DAX, design the SVG visually:59601. **Query the model first** -- use DAX Studio or Tabular Editor CLI to get actual values with the intended filter context. Use real numbers, not placeholders.612. **Write static SVG to a temp file** -- save to `/tmp/mockup.svg` and `open` it in a browser to preview layout, colors, and proportions.623. **Ask for feedback** before converting to DAX -- iterating on static SVG is far easier than on DAX string concatenation.634. **Colors must be hex codes with `#`** -- e.g., `fill='#2B7A78'`. Never use `%23` URL encoding or named colors. Always hex.6465### Step 1: Create the Extension Measure6667Create the extension measure in `reportExtensions.json` manually (see the `pbir-format` skill in the pbip plugin for JSON structure).6869```python70# Example using pbir_object_model (if available):71report.add_extension_measure(72 table="Orders",73 name="Sparkline SVG",74 expression='''75 VAR _Prefix = "data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 30'>"76 VAR _Bar = "<rect x='0' y='0' width='50' height='30' fill='#2196F3'/>"77 VAR _Suffix = "</svg>"78 RETURN _Prefix & _Bar & _Suffix79 ''',80 data_type="Text",81 data_category="ImageUrl",82 display_folder="SVG Charts",83)84report.save()85```8687### Step 1b: Review8889Before presenting the measure to the user, dispatch the `svg-reviewer` agent to validate syntax and provide design feedback.9091### Step 2: Bind to a Visual9293Extension measures use `"Schema": "extension"` in the SourceRef:9495```json96{97 "field": {98 "Measure": {99 "Expression": {100 "SourceRef": {"Schema": "extension", "Entity": "Orders"}101 },102 "Property": "Sparkline SVG"103 }104 }105}106```107108For **image visuals**, set `sourceType='imageData'` with `sourceField` in the visual.json (see `references/svg-image-visual.md`).109110### Step 3: Validate111112Validate JSON syntax with `jq empty <reportExtensions.json>` and inspect the file to confirm measure definitions and data categories.113114## Prefer UDF Libraries Over Custom DAX115116Before writing a custom SVG measure from scratch, check whether an existing UDF library already provides the chart type:117118- **PowerofBI.IBCS** (Andrzej Leszkiewicz) -- IBCS-compliant bar, column, waterfall, pin, small multiples, and P&L charts. Preferred for business reporting with AC/PY/BU/FC comparisons. Install from https://daxlib.org/package/PowerofBI.IBCS/119- **DaxLib.SVG** (Jake Duddy) -- general-purpose sparklines, bars, boxplots, heatmaps, jitter, violin, progress bars, pills. Install from https://daxlib.org/package/DaxLib.SVG/ -- source at https://github.com/daxlib/dev-daxlib-svg120- **PowerBI MacGuyver Toolbox** (Stepan Resl / Data Goblins) -- C# scripts that generate SVG measures via Tabular Editor121122To check if a library is installed, look for functions/measures starting with `PowerofBI.IBCS.`, `Viz.`, `Compound.`, or `Element.`. Only write custom SVG DAX when no library function covers the required visualization. See `references/community-examples.md` for full function listings and additional libraries.123124### Installing UDF libraries125126UDF libraries are installed into the semantic model, not the report. Use one of these tools:127128- **Tabular Editor CLI** (`te` command) -- use the `te-docs` skill for guidance129- **Power BI MCP server** -- if available, use it to modify the model directly130- **`connect-pbid` skill** -- connect to Power BI Desktop's local Analysis Services instance via TOM/PowerShell131- **`tmdl` skill** -- edit TMDL files directly in a PBIP project (last resort)132133## DAX SVG Conventions134135### Measure Structure (VAR Pattern)136137Every SVG measure must follow a strict VAR-based structure. Organize code into clearly separated regions:138139```dax140SVG Measure =141-- CONFIG: Input fields and visual parameters142VAR _Actual = [Sales Amount]143VAR _Target = [Sales Target]144VAR _Scope = ALLSELECTED ( 'Product'[Category] )145146-- CONFIG: Colors147VAR _BarColor = "#5B8DBE"148VAR _TargetColor = "#333333"149150-- NORMALIZATION: Scale values to SVG coordinate space151VAR _AxisMax = CALCULATE( MAXX( _Scope, [Sales Amount] ), REMOVEFILTERS( 'Product'[Category] ) ) * 1.1152VAR _AxisRange = 100153VAR _ActualNormalized = DIVIDE( _Actual, _AxisMax ) * _AxisRange154155-- SVG ELEMENTS: One VAR per visual element156VAR _SvgPrefix = "data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 25'>"157VAR _Sort = "<desc>" & FORMAT( _Actual, "000000000000" ) & "</desc>"158VAR _Bar = "<rect x='0' y='5' width='" & _ActualNormalized & "' height='15' fill='" & _BarColor & "'/>"159VAR _TargetLine = "<rect x='" & DIVIDE( _Target, _AxisMax ) * _AxisRange & "' y='2' width='2' height='21' fill='" & _TargetColor & "'/>"160VAR _SvgSuffix = "</svg>"161162-- ASSEMBLY: Combine in rendering order (back to front)163VAR _SVG = _SvgPrefix & _Sort & _Bar & _TargetLine & _SvgSuffix164165RETURN _SVG166```167168Key conventions:169- **CONFIG section first** -- input measures, scope column, colors, font settings. Users change only this section.170- **NORMALIZATION section** -- scale raw values to SVG coordinate space (see below)171- **SVG ELEMENTS** -- one VAR per `<rect>`, `<circle>`, `<text>`, `<line>`, etc.172- **ASSEMBLY** -- concatenate elements in document order (first = back layer, last = front)173- **`<desc>` sort trick** -- embed `FORMAT(_Actual, "000000000000")` in a `<desc>` tag so the table/matrix can sort by the SVG column174175### Axis Normalization (Critical)176177SVG coordinates must be normalized to a fixed range. Raw measure values (e.g., 1,234,567) cannot be used directly as pixel coordinates. The standard pattern:178179```dax180-- 1. Define the SVG coordinate range181VAR _BarMin = 0 -- leftmost position (or offset for labels)182VAR _BarMax = 100 -- rightmost position183184-- 2. Find the maximum value across all rows in the visual's filter context185VAR _Scope = ALLSELECTED( 'Table'[GroupColumn] )186VAR _MaxInScope = CALCULATE( MAXX( _Scope, [Measure] ), REMOVEFILTERS( 'Table'[GroupColumn] ) )187VAR _AxisMax = _MaxInScope * 1.1 -- 10% padding188189-- 3. Normalize each value to the SVG range190VAR _AxisRange = _BarMax - _BarMin191VAR _Normalized = DIVIDE( _Actual, _AxisMax ) * _AxisRange192```193194Use `ALLSELECTED` for the scope when the chart should respond to slicer context. Use `ALL` for a fixed axis across all filter contexts. The `* 1.1` padding prevents bars from touching the edge.195196### HASONEVALUE Guard197198Table/matrix SVG measures must guard against subtotal/total rows where multiple categories are in scope:199200```dax201IF( HASONEVALUE( 'Table'[GroupColumn] ),202 -- SVG code here203)204```205206Without this guard, the measure evaluates on grand total rows with meaningless aggregated values.207208### Escaping and Color Rules209210- **Single quotes for SVG attributes** -- avoids DAX double-quote escaping: `fill='#2196F3'`211- **Double quotes in DAX**: escape as `""` (DAX convention)212- **`viewBox`** for responsive scaling: `viewBox='0 0 100 25'`213- **`xmlns`** required on `<svg>` element214- **Hex colors with `#` only** -- e.g., `fill='#2196F3'`. `%23` URL encoding causes errors in image visuals. Never use named colors.215- **No JavaScript** -- SVG must be purely declarative216217### SVG Coordinate System218219- Y=0 is at the **top** -- invert values for charts: `_Height - _Value`220- Use `viewBox` with a 0-100 range for normalized coordinates221- Elements render in document order (first = back, last = front)222223### CONCATENATEX for Series Data224225For sparklines and multi-point charts, build coordinate strings with CONCATENATEX:226227```dax228VAR _Points = CONCATENATEX(229 _SparklineTable,230 [X] & "," & (100 - [Y]),231 " ",232 [Date], ASC233)234-- Produces: "0,80 10,60 20,40 30,20"235-- Use in: <polyline points='...'/>236```237238## Best Practices239240- Check UDF libraries first -- use DaxLib.SVG or MacGuyver Toolbox functions before writing custom DAX241- VAR pattern mandatory -- one VAR per config value, one VAR per SVG element, assembly at the end242- Normalize all values -- raw measure values must be scaled to SVG coordinate range243- HASONEVALUE guard -- always guard against total/subtotal rows in table/matrix context; use `ISINSCOPE` for nested hierarchy levels244- `<desc>` sort trick -- embed formatted value in `<desc>` for sortable SVG columns245- Use `viewBox` for responsive scaling instead of fixed width/height246- Round coordinates to integers for performance (shorter strings, cheaper FORMAT calls)247- Store as extension measures -- SVG measures don't belong in the semantic model248- Use `display_folder` to organize SVG measures (e.g., `"SVG Charts"`)249- Preview first -- save static SVG to `/tmp/`, open in browser, iterate before writing DAX250- 32K character limit on the rendered SVG string per cell (not the DAX expression); see `references/svg-table-matrix.md` for diagnosis and mitigation251- Pre-aggregate in model measures -- let the storage engine cache aggregations; the SVG measure maps numbers to coordinates only252- Hex colors only -- `#` directly, never `%23` URL encoding253- Image visuals need no `query` block -- only `objects.image` with `sourceType='imageData'` and `sourceField`254- Accessibility: every SVG encoding primary data needs adjacent readable columns and a dynamic alt-text measure; see `references/svg-accessibility.md`255256## reportExtensions.json Format257258```json259{260 "$schema": "https://developer.microsoft.com/json-schemas/fabric/item/report/definition/reportExtension/1.0.0/schema.json",261 "name": "extension",262 "entities": [{263 "name": "ExistingTable",264 "measures": [{265 "name": "Sparkline SVG",266 "dataType": "Text",267 "dataCategory": "ImageUrl",268 "expression": "...",269 "displayFolder": "SVG Charts"270 }]271 }]272}273```274275## Limitations276277- No interactivity -- SVG images are static (no hover, click, tooltip)278- No JavaScript -- inline scripts are stripped279- 32K character limit per rendered cell string (not the DAX expression); `CONCATENATEX` over 30+ series points easily approaches this; prefer `<polyline>` over individual shapes, integer coordinates, and pre-aggregated series; see `references/svg-table-matrix.md` for full diagnosis280- Per-cell formula-engine cost -- each visible cell evaluates the string-building expression; push aggregations into model measures so SVG assembly is coordinate-mapping only281- Accessibility gap -- screen readers receive no per-cell data from an SVG URI; mitigate with adjacent readable columns and dynamic alt text; see `references/svg-accessibility.md`282- Classic card (`card`) does NOT support SVG -- use `cardVisual` instead283284## When to Use SVG Measures285286SVG measures are the preferred choice for **simple inline graphics** embedded in tables, matrices, cards, and image visuals. Use SVG when you need:287288- Sparklines, data bars, progress bars, or status indicators inside table/matrix cells289- KPI micro-charts in card visuals290- Lightweight visuals that don't require interactivity or complex data transforms291- No additional custom visual registration (works with native visuals)292293**Use Deneb instead** for complex, interactive visualizations (cross-filtering, tooltips, hover states) or chart types that require extensive data transforms. **Use Python/R instead** for statistical analysis charts (distributions, regressions, correlations).294295## References296297### Community Examples and Libraries298299- **`references/community-examples.md`** -- Community SVG templates organized by target visual type (Table/Matrix, Image, Card), including DaxLib.SVG functions, Kerry Kolosko templates, and PowerBI MacGuyver Toolbox patterns300301### By Visual Type302303- **`references/svg-table-matrix.md`** -- Patterns for Table/Matrix: data bar, bullet chart, dumbbell, overlapping bars, lollipop, status pill, sparkline, bar sparkline, area sparkline, UDF patterns; axis normalization, sort trick, image size configuration, and per-cell performance guidance304- **`references/svg-image-visual.md`** -- Patterns for Image visuals: KPI header, sparkline with endpoint, dashboard tile; sourceType binding, dynamic/conditional layout, responsive width guidance305- **`references/svg-card-slicer.md`** -- Patterns for Card/Slicer: arrow indicator, mini gauge, mini donut, progress bar, narrative sentence; card binding via `callout.imageFX`306307### Accessibility308309- **`references/svg-accessibility.md`** -- Accessibility for SVG measures: adjacent readable columns, dynamic alt text, color-only encoding, contrast requirements, and severity guidance for audit findings310311### General312313- **`references/svg-elements.md`** -- SVG element reference (rect, circle, line, polyline, text, path, gradient, group)314315### Examples316317Ready-to-use DAX measure expressions in `examples/`:318- **`sparkline-measure.dax`** -- Line sparkline (polyline + CONCATENATEX)319- **`progress-bar-measure.dax`** -- Conditional progress bar320- **`dumbbell-chart-measure.dax`** -- Actual vs target dumbbell321- **`bullet-chart-measure.dax`** -- Bullet chart with sentiment action dots322- **`overlapping-bars-measure.dax`** -- Overlapping bars with variance label323- **`boxplot-measure.dax`** -- Box-and-whisker plot (inspired by DaxLib.SVG)324- **`ibcs-bar-measure.dax`** -- IBCS-compliant horizontal bar (inspired by avatorl)325- **`jitter-plot-measure.dax`** -- Dot strip chart with jitter (inspired by DaxLib.SVG)326- **`overlapping-bars-with-variance-measure.dax`** -- Overlapping bars with variance bar + arrow icon + % label (Kurt Buhler / Data Goblins)327- **`lollipop-conditional-measure.dax`** -- Lollipop with scaled dot + auto-formatted label (Kurt Buhler / Data Goblins)328- **`waterfall-measure.dax`** -- Waterfall with cumulative OFFSET positioning + connector lines (Kurt Buhler / Data Goblins)329- **`status-pill-measure.dax`** -- Rounded pill badge with category color + text label (Kurt Buhler / Data Goblins)330331## Helper Libraries332333| Library | Author | Key Features |334|---------|--------|--------------|335| DaxLib.SVG | Jake Duddy | UDF library: area, line, boxplot, heatmap, jitter, violin |336| PBI-Core-Visuals-SVG-HTML | David Bacci | Chips, tornado, gradient matrix, bar UDF |337| PowerBI MacGuyver Toolbox | Stepan Resl / Data Goblins | 20+ bar, 14+ line, 24+ KPI templates |338| Dashboard Design UDF Library | Dashboard-Design | Target line bars, pill visuals |339| Kerry Kolosko Templates | Kerry Kolosko | Sparklines, data bars, KPI cards |340341## Related Skills342343- **`pbi-report-design`** -- Layout and design best practices344- **`deneb-visuals`** -- Vega/Vega-Lite for complex interactive visualizations345- **`python-visuals`** -- matplotlib/seaborn for statistical charts346- **`r-visuals`** -- ggplot2 for statistical charts347- **`pbir-format`** (pbip plugin) -- PBIR JSON format reference (extension measures, ImageUrl binding)