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 Deku
I tried to apply your recommendation without success...
For example I created a calculation group with this kind of Items:
M =
VAR _Index =
MAXX(
FILTER(
'Calendar Fiscal',
'Calendar Fiscal'[TFS Date] = TODAY()
),
'Calendar Fiscal'[Index]
)
VAR _CurrentYear =
CALCULATE(
SELECTEDMEASURE(),
'Calendar Fiscal'[Index] = _Index
)
VAR _LastYear =
CALCULATE(
[Period],
'Calendar Fiscal'[Index]= _Index -12
)
VAR _Delta = _CurrentYear - _LastYear
VAR _Growth = DIVIDE(_Delta, _LastYear)
VAR _Color = IF(_Growth < 0, [ResultNeg_Color], [ResultPos_Color])
VAR _GrowthFormatted = FORMAT(_Growth, "+#%;-#%")
-- Dimensions ajustées pour la viewBox
VAR _SVGWidth = "100" -- Largeur en pourcentage
VAR _SVGHeight = "100" -- Hauteur en pourcentage
-- Ajustement dynamique pour le rectangle
VAR _Rect =
IF(
_Growth < 0,
"<rect x='0%' y='10%' width='3%' height='80%' rx='2' fill='" & [ResultNeg_Color] & "' />", -- Rectangle pour croissance négative
"<rect x='0%' y='10%' width='3%' height='80%' rx='2' fill='" & [ResultPos_Color] & "' />" -- Rectangle pour croissance positive
)
-- Création de l'image SVG avec les dimensions et ajustements dynamiques
VAR Img =
"
data:image/svg+xml;utf8,
<svg xmlns='http://www.w3.org/2000/svg' width='" & _SVGWidth & "%' height='" & _SVGHeight & "%'>
<!-- rectangle de couleur -->
" & _Rect & "
<!-- Texte pour l'année courante -->
<text x='5%' y='30%' font-family='Segoe UI' font-size='10' font-weight='Bold' fill='Black' text-anchor='start' 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='10' font-weight='Normal' fill='Gray' text-anchor='start' dominant-baseline='middle'>" & FORMAT(_LastYear,[FormatStringSelection]) & "</text>
<!-- Affichage du pourcentage de croissance -->
<text x='100%' y='30%' font-family='Segoe UI' font-size='10' font-weight='Bold' fill='" & _Color & "' text-anchor='end' dominant-baseline='middle'>" & _GrowthFormatted & "</text>
<!-- Affichage du delta -->
<text x='100%' y='70%' font-family='Segoe UI' font-size='8' font-weight='Normal' fill='" & _Color & "' text-anchor='end' dominant-baseline='middle'>" & FORMAT(_Delta,[FormatStringSelection]) & "</text>
</svg>
"
RETURN
IF(NOT(ISBLANK(_CurrentYear)), Img)I defined the calculation column as an Uncategorized data and I put it in the column field of my Matrix.
For the value field of the matrix, I put my metrics from a segment:
_Metric = {
("Quantity", NAMEOF('Measures Table'[Period_Qty]), 0),
("Revenues", NAMEOF('Measures Table'[Period_Revenues]), 1)
}And I defined the data type as an Image URL.
The final result is not what was expected
What am I doing wrong?
- Deku1 year ago
Super User
Not sure if there is a bug. I was playing with SVG yesterday. If I defined a measure that was the string for the SVG. That would work. If I called that measure in another measure it did not. Pretty sure it used to work.
- Kev591 year ago
Helper I
Arf **bleep** that don't arrange my case because I would like to apply different SVG output to my different Calculation items....
The only way I see is to use the old solution with only measures....