Skip to main content
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
wujunmin
New Contributor III

DIY Gradient Bar Chart by DAX+SVG

wujunmin_0-1632298769380.png

Measure: 

Bar = 
VAR CityCount =
    DISTINCTCOUNT ( 'table'[city] )
VAR Height =30
VAR MaxSales =
    MAXX ( ALLSELECTED('table'), [revenue] ) / 300
VAR Color=
"<defs>
    <LinearGradient id='wu'>
        <Stop offset='0%' style='stop-color:White'/>
        <Stop offset='100%' style='stop-color:DarkCyan'/>
    </LinearGradient>
</defs>"
VAR BarTable =
    ADDCOLUMNS (
        SUMMARIZE (
            'table',
            'table'[city],
            "index", RANKX ( ALLSELECTED ( 'table' ), [revenue],,, DENSE )
        ),
        "Rect",
            "<rect x='0' y='" & ( [index] - 1 ) * Height & "' width='" & [revenue] / MaxSales & "' height='" & Height-2 & " ' rx='15' ry='15' fill='url(#wu)' />",
        "Text",
            "<text x='2' y='"
                & ( [index] - 1 ) * Height
                    + INT ( Height * 0.6 ) & "' fill='black' text-anchor='left' font-size='"
                & INT ( Height * 0.6 ) & "' >" & [city] & "["
                & ROUND ( [revenue], 0 ) & "]" & "</text>"
    )
VAR Bar =
    CONCATENATEX ( BarTable, [Rect] & [Text] )
VAR SVG = "<svg xmlns='http://www.w3.org/2000/svg' height='"&Height*CityCount&"' width='300' >" &Color& Bar & "</svg>"
RETURN
    IF ( HASONEVALUE ( 'table'[province] ), SVG, BLANK () )

 

0 REPLIES 0

Helpful resources

Announcements
Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Users online (153)