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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
swasim
Helper I
Helper I

DAX Measure for Conditional Color for Sparklines (SVG format)

Hi ,

 

Need help from experts , my client requirements

1) Draw a Sparkline using SVG  (Was able to get done)

2) Based on selected Date Filter , Sparkline should be charted for last 4 quarters. (Was able to get done)

3) Client wants to change Line color using  Linear Gradient based on the condition (Result Field )(I am having difficulty and need help)

 

If Value of Result is good  then  "#178757"  --green
If Value of Result is Bad then "#D71e28"   --red
if Value of Result is Aver then "#FFD100"  --Yellow
 
Attached the actual PBIX file and data for your reference. Can someone help here , having difficulty is drawing Line colors.
 
 
 
 
7 REPLIES 7
lbendlin
Super User
Super User

Gradients are defined a little different than your sample code.

 

Gradients in SVG - SVG: Scalable Vector Graphics | MDN (mozilla.org)

 

VAR Defs = "<defs>
    <linearGradient id='grad' x1='0' y1='25' x2='0' y2='50' gradientUnits='userSpaceOnUse'>
        <stop stop-color='green' offset='0' />
        <stop stop-color='yellow' offset='50%' />
        <stop stop-color='red' offset='1' />
    </linearGradient>
</defs>"

lbendlin_0-1715003473574.png

 

Yes , i dont know . Th Gradients i just copied from internet and i dont know how to resolve.  how do we pass to the PBI sparkline based on condition. 

I dont want this hardcoding. Line color should be based on the condition in the excel.

 

<stop stop-color='green' offset='0' />
        <stop stop-color='yellow' offset='50%' />
        <stop stop-color='red' offset='1' />

 

Its based on the color from excel. Already based on the condition the color coding is in the excel.

 

Your conditions change over time. That means you cannot use lines for the coloring, you would need to use single dots and color these accordingly.

Could you update the PBIX file and send me.

No, you need to rethink your approach.  A common visual for your scenario could be a box and whiskers scatter plot, or a Deneb custom visual.

THis is rough sketch.  I am looking at solution like this for last 4 quarters with different line colot. Is this possible ? 

 

swasim_0-1715015184222.png

 

yes, that is possible, but I don't see how this would be useful to your report users.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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