DAX SVG measure · Status

Star ratings in Power BI with a DAX SVG measure

Most star-rating tricks round to whole stars with REPT and a Unicode star. This measure draws the empty row, then the filled row clipped to the exact rating with a nested SVG, so 3.7 fills seven tenths of the fourth star.

By · Founder & Reliability Engineer · Updated

Rating stars rendered from the DAX below with sample data
Rendered from the measure below with sample data at 2× (78×14 px in Power BI). 1,031 characters.

Use it when

  • Customer, product or supplier ratings on a fixed scale (1–5, 1–10).
  • A familiar visual shorthand matters more than precision.

Skip it when

Differences of a tenth are decisions (4.6 vs 4.7 supplier ranking): print the number; stars hide small gaps.

Three looks

The rating stars in three palettes; click one to edit it.

Data it needs

The builder asks for exactly these fields; type your own measure and column names there.

Rating measure
On the same scale as the number of stars, usually AVERAGE of a rating column.

The full DAX

Swap [Avg Rating] for your own names.

Rating Stars (measure)
Rating Stars =
-- VizForge SVG measure: 5-star rating with partial fill.
-- Set Measure tools > Data category = Image URL, then size it under Format > Visual > Image size.
-- Values are clamped to 0 and the number of stars.
-- Made with the free VizForge SVG measure builder: vizforge.ai/tools/svg-measure-builder
-- Need per-point tooltips, click-to-select inside the chart or Format-pane settings? Generate it as a real custom visual: vizforge.ai/visuals
VAR _Rating = MAX ( 0, MIN ( 5, [Avg Rating] ) )
VAR _Full = INT ( _Rating )
RETURN
    IF (
        ISBLANK ( [Avg Rating] ),
        BLANK (),
        "data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='78' height='14' viewBox='0 0 78 14'><path d='M7 0.6L8.9 5L13.7 5.4L10 8.5L11.1 13.2L7 10.7L2.9 13.2L4 8.5L0.3 5.4L5.1 5ZM23 0.6L24.9 5L29.7 5.4L26 8.5L27.1 13.2L23 10.7L18.9 13.2L20 8.5L16.3 5.4L21.1 5ZM39 0.6L40.9 5L45.7 5.4L42 8.5L43.1 13.2L39 10.7L34.9 13.2L36 8.5L32.3 5.4L37.1 5ZM55 0.6L56.9 5L61.7 5.4L58 8.5L59.1 13.2L55 10.7L50.9 13.2L52 8.5L48.3 5.4L53.1 5ZM71 0.6L72.9 5L77.7 5.4L74 8.5L75.1 13.2L71 10.7L66.9 13.2L68 8.5L64.3 5.4L69.1 5Z' fill='%23E6E6E6'/><svg width='"
            & FORMAT ( _Full * 16 + ( _Rating - _Full ) * 14, "0.0", "en-US" )
            & "' height='14' overflow='hidden'><path d='M7 0.6L8.9 5L13.7 5.4L10 8.5L11.1 13.2L7 10.7L2.9 13.2L4 8.5L0.3 5.4L5.1 5ZM23 0.6L24.9 5L29.7 5.4L26 8.5L27.1 13.2L23 10.7L18.9 13.2L20 8.5L16.3 5.4L21.1 5ZM39 0.6L40.9 5L45.7 5.4L42 8.5L43.1 13.2L39 10.7L34.9 13.2L36 8.5L32.3 5.4L37.1 5ZM55 0.6L56.9 5L61.7 5.4L58 8.5L59.1 13.2L55 10.7L50.9 13.2L52 8.5L48.3 5.4L53.1 5ZM71 0.6L72.9 5L77.7 5.4L74 8.5L75.1 13.2L71 10.7L66.9 13.2L68 8.5L64.3 5.4L69.1 5Z' fill='%23D9B300'/></svg></svg>"
    )
DAX user-defined function variant (VizForge.SvgRatingStars)

One-line call: Rating Stars = VizForge.SvgRatingStars ( [Avg Rating] )

DAX query view script
-- 1) Paste into DAX query view and choose 'Update model with changes'.
--    Needs DAX user-defined functions (generally available since the June 2026 Power BI release).
DEFINE
    /// Rating stars as an SVG image URL (VizForge). Optional parameters default to the colours you picked.
    FUNCTION VizForge.SvgRatingStars = (
            pValue : NUMERIC,
            pEmptyColor : STRING = "#E6E6E6",
            pStarColor : STRING = "#D9B300"
        ) =>
        VAR _Rating = MAX ( 0, MIN ( 5, pValue ) )
        VAR _Full = INT ( _Rating )
        RETURN
            IF (
                ISBLANK ( pValue ),
                BLANK (),
                "data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='78' height='14' viewBox='0 0 78 14'><path d='M7 0.6L8.9 5L13.7 5.4L10 8.5L11.1 13.2L7 10.7L2.9 13.2L4 8.5L0.3 5.4L5.1 5ZM23 0.6L24.9 5L29.7 5.4L26 8.5L27.1 13.2L23 10.7L18.9 13.2L20 8.5L16.3 5.4L21.1 5ZM39 0.6L40.9 5L45.7 5.4L42 8.5L43.1 13.2L39 10.7L34.9 13.2L36 8.5L32.3 5.4L37.1 5ZM55 0.6L56.9 5L61.7 5.4L58 8.5L59.1 13.2L55 10.7L50.9 13.2L52 8.5L48.3 5.4L53.1 5ZM71 0.6L72.9 5L77.7 5.4L74 8.5L75.1 13.2L71 10.7L66.9 13.2L68 8.5L64.3 5.4L69.1 5Z' fill='"
                    & SUBSTITUTE ( pEmptyColor, "#", "%23" )
                    & "'/><svg width='"
                    & FORMAT ( _Full * 16 + ( _Rating - _Full ) * 14, "0.0", "en-US" )
                    & "' height='14' overflow='hidden'><path d='M7 0.6L8.9 5L13.7 5.4L10 8.5L11.1 13.2L7 10.7L2.9 13.2L4 8.5L0.3 5.4L5.1 5ZM23 0.6L24.9 5L29.7 5.4L26 8.5L27.1 13.2L23 10.7L18.9 13.2L20 8.5L16.3 5.4L21.1 5ZM39 0.6L40.9 5L45.7 5.4L42 8.5L43.1 13.2L39 10.7L34.9 13.2L36 8.5L32.3 5.4L37.1 5ZM55 0.6L56.9 5L61.7 5.4L58 8.5L59.1 13.2L55 10.7L50.9 13.2L52 8.5L48.3 5.4L53.1 5ZM71 0.6L72.9 5L77.7 5.4L74 8.5L75.1 13.2L71 10.7L66.9 13.2L68 8.5L64.3 5.4L69.1 5Z' fill='"
                    & SUBSTITUTE ( pStarColor, "#", "%23" )
                    & "'/></svg></svg>"
            )

EVALUATE { VizForge.SvgRatingStars ( [Avg Rating] ) }

-- 2) Then create the measure and set Measure tools > Data category = Image URL:
-- Rating Stars = VizForge.SvgRatingStars ( [Avg Rating] )
--    Colours and thresholds are optional parameters: pass a value after the fields to override one.
--    Pass colours as plain "#RRGGBB"; the function encodes the # for the data URI.

Placing it in a report

78 × 14 for five stars at the default size; widen it in proportion if you set ten stars. Put [Avg Rating] and a review count next to it so the stars don't stand alone. Remember the Image URL data category. All setup steps.

Gotchas

When an SVG measure isn't enough

A custom visual can show the rating distribution on hover and filter reviews by star band.

KPI card designs using it

Finished designs built on this pattern, from the KPI card gallery.