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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
wujunmin
Advocate I
Advocate I

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors