Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Get a single value into an SVG Measure

Hello,

 

I have created a Pie Chart SVG Measure for which I have to procure an integer that represents the score. The SVG then produces a pie chart with the score.

 

Here is SVGpourcentage :

SVGPourcentage = 

var __note = 

var __pourcent = __note / 10 *100

//create svg code

VAR __mid = 
"
<circle r='73' cx='75' cy='75' fill='tomato' />
  <circle r='36.5' cx='75' cy='75' fill='transparent'
    stroke='YellowGreen'
    stroke-width='73'
    stroke-dasharray='calc("&__pourcent&" * 458.67 / 100) 468.57'
    transform='rotate(-90) translate(-150)'/>"

//create beginning svg code
var __beg = 
"data&colon;image/svg+xml;utf-8,
<svg xmlns='http://www.w3.org/2000/svg' x='0px' y='0px'
    width='150'
    height='150'
    viewBox='0 0 150 150' >"

//mark the svg end
var __end= " </svg>"

// return all parts
return
__beg&__mid&__end

 

 

As you can see, i need to get a single value to __note, an integer between 0 and 10. 

These values are on table named table1 (some fields are empty for now) :

 

How can I fetch these values individually from the measure Dax ? I have a feel this isn't possible but I do not know how to do it else.

 

Thanks

James

 

 

  • Anonymous's avatar
    Anonymous
    4 years ago

    I finaly got it to work.

     

    The problem was in the SVG code, specificcaly the line 

    stroke-dasharray='calc("&__pourcent&" * 458.67 / 100) 468.57'

    The numbers 458.67 and 468.57 should be the same, and depend on the circonference of the circle, here 229.33 because radius = 36,5.

    So the correct line is 

    stroke-dasharray='calc("&__pourcent&" * 229.3363 / 100 ) 229.3363' 

    and Power Query/BI returns the correct value by any mean. 

     

    Problem solved

7 Replies

  • v-yalanwu-msft's avatar
    v-yalanwu-msft
    Icon for Community Support rankCommunity Support

    Hi, Anonymous ;

    Can you post sample data as text and expected output?
    Not enough information to go on;

    The most important parts are:
    1. Sample data as text, use the table tool in the editing bar
    2. Expected output from sample data
    3. Explanation in words of how to get from 1. to 2.


    Best Regards,
    Community Support Team _ Yalan Wu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Sure, I'll Try to answer best I can ;

       

      As you can see, the code I posted is HTML/SVG code. It defines an image in SVG format (scalar vector).

      In this code I have avriable named " __pourcent". I want to assign a value to this variable, and tha values are the one in the calculated column I posted aswell. Now the HTML-SVG code is stored in a measure, So I guess the question is : How do I fetch one value in a column from a measure ?

      I'm asking for the DAX code that would alow me to reach one single value from a specific column.

       

      Now about your requirement ;

      1) I can't post any sample data as they're confidential. Nonetheless, I can picture the expected output :

      2) 

      I want to diasplay a table visual. Each line from this visual is a line from a Table1. My Table1 has a "score" column I show in the main post. Instead of displaying a score as a number, I want to show it as a pie chart just like the picture above. 

      3) I miss the dax code to get from my value in the score column into a measure that diasplays the pie chart.

  • v-yalanwu-msft's avatar
    v-yalanwu-msft
    Icon for Community Support rankCommunity Support

    Hi, Anonymous ;

    From what I understand, you want the output to have a corresponding pie chart for each row, right? I might think this is impossible, dax can only output numbers and text. may be could use if().


    Best Regards,
    Community Support Team _ Yalan Wu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Yes, I want each line to ouput its score into a pice chart which represents the score on a maximum of 10.

      I'll still look a bit around to figure out wether there's a way, and I'll post the solution there If i get one.

       

    • Anonymous's avatar
      Anonymous
      Not applicable

      It would appear I need a SUM measure that doesn't not change on Row context ?

  • v-yalanwu-msft's avatar
    v-yalanwu-msft
    Icon for Community Support rankCommunity Support

    Hi, Anonymous ;

    Or can you share a simple example of no sensitive information, and desired output results? I'll see if I can do it again


    Best Regards,
    Community Support Team _ Yalan Wu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • Anonymous's avatar
    Anonymous
    Not applicable

    I finaly got it to work.

     

    The problem was in the SVG code, specificcaly the line 

    stroke-dasharray='calc("&__pourcent&" * 458.67 / 100) 468.57'

    The numbers 458.67 and 468.57 should be the same, and depend on the circonference of the circle, here 229.33 because radius = 36,5.

    So the correct line is 

    stroke-dasharray='calc("&__pourcent&" * 229.3363 / 100 ) 229.3363' 

    and Power Query/BI returns the correct value by any mean. 

     

    Problem solved