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
kbraga
Helper I
Helper I

Trouble filling SVG icon with color

I'm trying to fill an SVG icon with a color to show the percentage complete towards a specific goal. The goal is 100 hours volunteered and my data lists the number of hours volunteered per person (column name: [Hours volunteered]. I have two questions: (1) what should my measure to show the percentage of hours volunteered compared to the goal of 100? and (2) how should it be incorprated into my SVG KPI measure? For the latter, I currently have the following but it is not working correctly:  

 

----

 

Icon KPI =
// svg essentials
var svg_start = "data&colon;image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'>"
var svg_end = "</svg>"

//def clip path
var clip_height = (DIVIDE([Hours Volunteered],300,000)) * 100
var clip_y = 100 - clip_height
var defs = "<defs><clipPath id='iconClip'>
<rect x='0' y='" & clip_y & "' width='96' height='" & clip_height & "' />
</clipPath></defs>"


// Color
var grey_icon = "<g style='fill:grey;'>" & [Celebration Icon SVG] & "</g>"
var red_icon = "<g style='fill:red; clip-path:url(#iconClip)'>" & [Celebration Icon SVG] & "</g>"

//combine SVG Parts
return
svg_start & defs & grey_icon & red_icon & svg_end
4 REPLIES 4
v-xicai
Community Support
Community Support

Hi  @kbraga  ,

 

Do the suggestions from engineers make sense? If so, kindly mark the proper reply as a solution to help others having the similar issue and close the case. If not, let me know and I'll try to help you further.

 

Best regards

Amy

Greg_Deckler
Super User
Super User

@kbraga - See if these SVG examples help:

https://community.powerbi.com/t5/forums/searchpage/tab/message?advanced=false&allow_punctuation=fals...


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
kbraga
Helper I
Helper I

To get the above, I tried to follow this tutorial: https://hatfullofdata.blog/svg-in-power-bi-part-3/

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.