cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
john4614
Frequent Visitor

Spark line not showing in column of table matrix

Hello everyone, I am experiencing a problem with a sparkline I setup within a column. I do not get any errors in my DAX code and I changed the value for to Image-URL. It seems like a box for the sparkline gets created for the column but there is no image in it. I wonder what could be the issue. Below is my code:

 

 

 

Sparkline = 
// Static line color
VAR LineColor = "#01B8AA"
// "Date" field used in this example along the X axis
VAR XMinDate = MIN(Kalender[MaandNr])
VAR XMaxDate = MAX(Kalender[MaandNr])
// Obtain overall min and overall max measure values when evaluated for each date
VAR YMinValue = MINX(VALUES(Kalender[MaandNr]),CALCULATE([Actuals2]))
VAR YMaxValue = MAXX(VALUES(Kalender[MaandNr]),CALCULATE([Actuals2]))
// Build table of X & Y coordinates and fit to 100 x 100 viewbox
VAR SparklineTable = ADDCOLUMNS(
    SUMMARIZE(Kalender,Kalender[MaandNr]),
        "X",INT(100 * DIVIDE(Kalender[MaandNr] - XMinDate, XMaxDate - XMinDate)),
        "Y",INT(100 * DIVIDE([Actuals2] - YMinValue,YMaxValue - YMinValue)))
// Concatenate X & Y coordinates to build the sparkline
VAR Lines = CONCATENATEX(SparklineTable,[X] & "," & 100-[Y]," ", [MaandNr])
// Add to SVG, and verify Data Category is set to Image URL for this measure
VAR SVGImageURL = IF(HASONEVALUE('KPI Data (2)'[Actual]),
    "data:image/svg+xml;utf8," & 
    "<svg xmlns='http://www.w3.org/2000/svg' x='0px' y='0px' viewBox='0 0 30 120'>" &
     "<polyline fill='none' stroke='" & LineColor & 
     "' stroke-width='5' points='" & Lines & 
     "'/></svg>",
     BLANK())
RETURN SVGImageURL

 

 

 

9 REPLIES 9
v-deddai1-msft
Community Support
Community Support

Hi @john4614 ,

 

No, you just need to set them in measure. Please refer to https://www.w3schools.com/graphics/svg_polyline.asp

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Best Regards,

Dedmon Dai

 

 

v-deddai1-msft
Community Support
Community Support

Hi @john4614 ,

 

Would you please try to change the last part of your code to:

 

VAR SVGImageURL = IF(HASONEVALUE('KPI Data (2)'[Actual]),
"data : image/svg+xml;utf8," &
"<svg xmlns='http://www.w3.org/2000/svg' x='0px' y='0px' viewBox='0 0 30 120'>" &
"<polyline fill='none' stroke='" & LineColor &
"' stroke-width='5' points='" & Lines &
"'/></svg>",
BLANK())

 

 

 

For more details, please refer to https://gist.github.com/deldersveld/62523ca8350ac97797131560cb317677

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Best Regards,

Dedmon Dai

Thanks for the reply, however it is still not rendering the image. I think it must be a small issue somewhere but I do not know what it could be.

Hi @john4614 ,

 

Just based on my test, the code I use can render the image:

Capture.PNG

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Best Regards,

Dedmon Dai

 

Okay, I tried your exact test code on my company laptop and personal PC and both got this broken image. I also used the image url category. Do I need to check my settings?

Hi Dedmon, thanks for the info. It seems like it helps. It looks like the image just doesn't want to render.
afbeelding.PNG

Hi @john4614 ,

 

I have edit my original reply, please pay attention to the bold part.

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Best Regards,

Dedmon Dai

 

 

lbendlin
Super User
Super User

what's the rationale behind:

 

IF(HASONEVALUE('KPI Data (2)'[Actual])

 ?

Hi, I think that was a little mistake. Now I placed the category there instead.

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors