Forum Discussion
Dax - Calculation group and SVG output
- 1 year ago
Hi Kev59 ,
Since you have reverted to your previous setup, if any of the responses helped resolve the issue or guided you toward the resolution, kindly consider marking it as the accepted solution. This helps others in the community who may face a similar problem. Thank you!
Thank you!!
The only thing you can do is define the SVG in the calculation group and pass in a specific measure with selectedvalue() for some kind of rendering. If it is a sparkline or bar chart you have to have a predefined axis.
I've tried before and they are hard to mix, but entirely depends on the specifics of your SVG and what calculations you need to perform.
Hi
I tired to define the SVG in the calculation items but that didn't work...
For the moment the only way I find is the put the SVG formatting in a measure:
Status SVG =
VAR _CurrentYear = [Period]
VAR _LastYear =
CALCULATE(
[Period],
SAMEPERIODLASTYEAR('Calendar Fiscal'[TFS Date])
)
VAR _Delta = _CurrentYear - _LastYear
VAR _Growth = DIVIDE(_Delta, _LastYear)
VAR _Color = IF(_Growth < 0, [ResultNeg_Color], [ResultPos_Color])
VAR _GrowthFormatted = FORMAT(_Growth, "0%")
-- Dimensions ajustées pour la viewBox
VAR _SVGWidth = 75
VAR _SVGHeight = 25
VAR _FontWeight = "500"
VAR X_Arrow = 27
VAR Y_Arrow = 0
-- SVG design pour les flèches
VAR _Arrow =
IF(
_Growth < 0,
"<path d='M10 10 L15 15 L20 10 Z' fill='" & [ResultNeg_Color] & "' transform='translate(" & X_Arrow & "," & Y_Arrow & ")' />", -- Flèche vers le bas
"<path d='M10 15 L15 10 L20 15 Z' fill='" & [ResultPos_Color] & "' transform='translate(" & X_Arrow & "," & Y_Arrow & ")' />" -- Flèche vers le haut
)
-- Création de l'image SVG
VAR Img =
"
data:image/svg+xml;utf8,
<svg xmlns='http://www.w3.org/2000/svg' width='" & _SVGWidth & "' height='" & _SVGHeight & "'>
<!-- Texte pour l'année courante -->
<text x='5%' y='30%' font-family='Segoe UI' font-size='6' font-weight='" & _FontWeight & "' fill='Black' text-anchor='left' dominant-baseline='middle'>" & FORMAT(_CurrentYear,[FormatStringSelection]) & "</text>
<!-- Texte pour l'année précédente -->
<text x='5%' y='70%' font-family='Segoe UI' font-size='5' font-weight='" & _FontWeight & "' fill='Gray' text-anchor='left' dominant-baseline='middle'>" & FORMAT(_LastYear,[FormatStringSelection]) & "</text>
<!-- Flèche positionnée dynamiquement -->
" & _Arrow & "
<!-- Affichage du delta -->
<text x='85%' y='30%' font-family='Segoe UI' font-size='4' font-weight='" & _FontWeight & "' fill='" & _Color & "' text-anchor='middle' dominant-baseline='middle'>" & FORMAT(_Delta,[FormatStringSelection]) & "</text>
<!-- Affichage du pourcentage de croissance -->
<text x='85%' y='60%' font-family='Segoe UI' font-size='4' font-weight='" & _FontWeight & "' fill='" & _Color & "' text-anchor='middle' dominant-baseline='middle'>" & _GrowthFormatted & "</text>
</svg>
"
RETURN
IF(NOT(ISBLANK(_CurrentYear)), Img)
but the calculation is made two time...
the output is like below: