cancel
Showing results for 
Search instead for 
Did you mean: 
Accepted Solution

SVG Trend Indicator

10799 Views
Highlighted
dgwilson Member
Member

SVG Trend Indicator

Just like SVG SparkLines this DAX produces a Trend indicator, Up/Down/Neutral.

Add it as a field in your table, keyed off a numeric value to give you the up/down/neutral.

One additional trick is to set the image size as small as possible (24) under Grid as part of the formatting.

 

SVG Trend Indicator.PNG

Trend_Image =

    VAR MessageText = ""

    VAR Radius = 9

    VAR Colour = "blue"

    VAR Opacity = 0.75

    VAR SVG_Neutral = "data:image/svg+xml;utf8," &

              "<svg xmlns='http://www.w3.org/2000/svg' x='0px' y='0px' width='50' height='20'>" &

              "<circle cx='25' cy='10' r='" & Radius & "' fill='" & Colour & "' fill-opacity='" & Opacity & "' />" &

              "</svg>"

    VAR SVG_UP = "data&colon;image/svg+xml;utf8," &

              "<svg xmlns='http://www.w3.org/2000/svg' x='0px' y='0px' width='50' height='20'>" &

              "<polygon points=""05,20 45,20 25,1"" style=""fill:green;stroke:green;stroke-width:0;fill-rule:evenodd;"" />" &

              "</svg>"

    VAR SVG_DN = "data&colon;image/svg+xml;utf8," &

              "<svg xmlns='http://www.w3.org/2000/svg' x='0px' y='0px' width='50' height='20'>" &

              "<polygon points=""05,1 45,1 25,20"" style=""fill:red;stroke:red;stroke-width:0;fill-rule:evenodd;"" />" &

              "</svg>"

RETURN

    IF('Customer KPI'[KPI_Trend] > 0, SVG_UP, IF('Customer KPI'[KPI_Trend] < 0, SVG_DN, SVG_Neutral))

 


Accepted Solutions
dgwilson Member
Member

Re: SVG Trend Indicator

Thank you.

 

Yes an issue with copy & paste. and Having tried it again, the editor here is doing "fancy" stuff that I cannot work around.

The "magic" is attached in an image below.

 

 

ThatTextForSVG.PNG

View solution in original post


All Replies
tomknight Regular Visitor
Regular Visitor

Re: SVG Trend Indicator

Thanks a lot for posting this - it's fantastic!

 

The DAX didn't work out of the box for me (I got the broken image icon) but I followed the link in your other DAX based sparkline post and saw that the prefix for the SVG data was slightly different. I think the forum is changing the code when you save it.

 

If you replace the "&colon;" in the code with an actual colon it works perfectly.

 

Thanks again,


Tom

dgwilson Member
Member

Re: SVG Trend Indicator

Thank you.

 

Yes an issue with copy & paste. and Having tried it again, the editor here is doing "fancy" stuff that I cannot work around.

The "magic" is attached in an image below.

 

 

ThatTextForSVG.PNG

View solution in original post

tomknight Regular Visitor
Regular Visitor

Re: SVG Trend Indicator

Hi,

 

Does this work for you in a total row?

 

It doesn't seem to work for me and I don't know why. It should calculate exactly the same shouldn't it?

 

Thanks,


Tom

dgwilson Member
Member

Re: SVG Trend Indicator

That's a good question. I haven't used it in a total row.

tomknight Regular Visitor
Regular Visitor

Re: SVG Trend Indicator

This doesn't seem to work in the latest update of PowerBI service - I get a missing image placeholder instead of the SVG. Any idea why that might be? It still works fine in PBI Desktop but not in the service.

 

Thanks,


Tom

dgwilson Member
Member

Re: SVG Trend Indicator

Likely a browser issue. Or browser version issue.

Does it work in Chrome?

 

- David

tomknight Regular Visitor
Regular Visitor

Re: SVG Trend Indicator

Strangely it doesn’t work in Chrome or Firefox but it does work in Edge - never seen in issue like this that way round, its usually vice versa. I’ve raised a ticket with Microsoft so will see what they say.

Thanks,

Tom
dgwilson Member
Member

Re: SVG Trend Indicator

That's really weird. "Everything" works in Chrome.

The SVG code that you have (or are generating)... you can place in a txt file xyz.svg and open that in the browser... so you can test outside of Power BI. There maybe something in the SVG code or headers that is breaking the browser compatability?

 

- David

tomknight Regular Visitor
Regular Visitor

Re: SVG Trend Indicator

Just tried that and the SVG is sound. I have deployed this with different SVGs in 3 different projects and they all simultanously broke with the Feb update of PBI so there must be a change in PBI somewhere. I thought it might be due to "external" images so I took the URL of an SVG that I found online and put it into a table and set it to Web Image but that worked fine.

 

Will keep you posted with what Microsoft say. They've asked for the PBIX file.

 

Thanks for the help,

 

Tom