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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
tarunbisht20001
Frequent Visitor

Need help!!!!!

I have this measure as below.

StackedBarChart =
VAR BarHeight = 80  
VAR MaxWidth = 600
VAR BarY = 50
VAR FontSize = 43
VAR FontWeight = "bold"  
VAR MinWidth = MaxWidth * 0.15  
VAR Color1 = "#FF0000"  
VAR Color2 = "#FFC107"  
VAR Color3 = "#4CAF50"
VAR TextColor = "#000000"
VAR TotalValue = [Red Count] + [Amber Count] + [Green Count]
VAR Width1 = MAX(DIVIDE([Red Count], TotalValue, 0) * MaxWidth, MinWidth)
VAR Width2 = MAX(DIVIDE([Amber Count], TotalValue, 0) * MaxWidth, MinWidth)
VAR Width3 = MAX(DIVIDE([Green Count], TotalValue, 0) * MaxWidth, MinWidth)
VAR CountStr1 = IF([Red Count] = 0, "", FORMAT([Red Count], "#,0"))
VAR CountStr2 = IF([Amber Count] = 0, "", FORMAT([Amber Count], "#,0"))
VAR CountStr3 = IF([Green Count] = 0, "", FORMAT([Green Count], "#,0"))
VAR XPos1 = 0
VAR XPos2 = IF([Red Count] > 0, XPos1 + Width1, 0)
VAR XPos3 = IF([Amber Count] > 0, XPos2 + Width2, IF([Red Count] > 0, XPos1 + Width1, 0))
VAR SVG =
    "data&colon;image/svg+xml;utf8,<svg width='700' height='200' xmlns='http://www.w3.org/2000/svg'>" &
    IF([Red Count] > 0,
        "<rect width='" & Width1 & "' height='" & BarHeight & "' x='" & XPos1 & "' y='" & BarY & "' fill='" & Color1 & "' />" &
        "<text x='" & (XPos1 + Width1 / 2) & "' y='" & (BarY + BarHeight / 2 + FontSize / 10) & "' font-family='Arial' font-size='" & FontSize & "' font-weight='" & FontWeight & "' fill='" & TextColor & "' text-anchor='middle'>" & CountStr1 & "</text>",
        ""
    ) &
    IF([Amber Count] > 0,
        "<rect width='" & Width2 & "' height='" & BarHeight & "' x='" & XPos2 & "' y='" & BarY & "' fill='" & Color2 & "' />" &
        "<text x='" & (XPos2 + Width2 / 2) & "' y='" & (BarY + BarHeight / 2 + FontSize / 10) & "' font-family='Arial' font-size='" & FontSize & "' font-weight='" & FontWeight & "' fill='" & TextColor & "' text-anchor='middle'>" & CountStr2 & "</text>",
        ""
    ) &
    IF([Green Count] > 0,
        "<rect width='" & Width3 & "' height='" & BarHeight & "' x='" & XPos3 & "' y='" & BarY & "' fill='" & Color3 & "' />" &
        "<text x='" & (XPos3 + Width3 / 2) & "' y='" & (BarY + BarHeight / 2 + FontSize / 10) & "' font-family='Arial' font-size='" & FontSize & "' font-weight='" & FontWeight & "' fill='" & TextColor & "' text-anchor='middle'>" & CountStr3 & "</text>",
        ""
    ) &
    "</svg>"
RETURN
    SVG

I am using this major in matrix visual with other column, problem i am facing is this measure is causing bypasing of the selection in slicer, there is no error or issue in the red, amber and green count measure as i return either of them instead of svg measure repspects the selection in slicers.

I tried making a calculated column but that is not giving me required image, even tho it resolved the bypassing issue.
 
2 REPLIES 2
AmiraBedh
Most Valuable Professional
Most Valuable Professional

I have a doubt that your measure is not respecting the filtering context and  accidentally resetting or overriding it.

 

For example, when calculating Red Count, Amber Count, and Green Count, ensure that they properly respect the filter context:

VAR RedCount = CALCULATE([Red Count], KEEPFILTERS(YourTable))

VAR AmberCount = CALCULATE([Amber Count], KEEPFILTERS(YourTable))

VAR GreenCount = CALCULATE([Green Count], KEEPFILTERS(YourTable))

 

 

Since the measure is being used in a matrix visual, try explicitly defining how the matrix should interact with other visuals. 

You can manage the filtering behavior under the "Edit Interactions" options in Power BI. 

Since you mentioned that using a calculated column resolves the bypassing issue but doesn't display the image correctly, this suggests the dynamic nature of the measure might be part of the problem. While calculated columns lack flexibility in filtering, a workaround could be to precalculate values or store them in a way that still allows for dynamic rendering without bypassing.

 

Alternatively, you can create calculated columns for Red Count, Amber Count, and Green Count and a measure for the SVG part, keeping it separate from the counts themselves.

 


Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696

Red Count, Amber Count, and Green Count are not causing the issue actually, when i return total count or either of them instead of SVG it do not causes the issue but when i return any static valu like max width,SVG and all it causes the bypassing.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.