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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Kev59
Helper I
Helper I

Dax - Calculation group and SVG output

Dear all

 

I would like to use calculation group for basic calculations (M1, M2... QTD, YTD) but I would like to combine that with a svg output in my matrix with different information:

* value of the current period

* value of previous period

* Delta

* Arrow (red or green) based on the delta value

 

Is it possible to do that in a calculation group? Do you have example to share?

 

In my matrix, I put the column calculation group as column and the segment values (metric selection) as values.

Where do I need to apply the svg formatting? directly in the calculation group items or in the value item of my matrix?

 

Another issue: my dateset is based on 2 calendar (normal and Fiscal linked) and I'm not able to use the DATEQTD etc... functions. I don't know why. do you have any idea?

 

1 ACCEPTED SOLUTION

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!!

View solution in original post

12 REPLIES 12
v-sathmakuri
Community Support
Community Support

Hi @Kev59 ,

May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.

Thank you.

Hi 

 

unfortunately not like I would like... so I moved back to the previous position (Calculation group and basic conditonnal formatting)

 

BR

Hi @Kev59 ,

 

Thanks for the update. It seems the previous thread didn’t fully resolve the issue and reverting to the previous setup makes sense for now. 
Please let us know if you need any further assistance.

 

Thank you!!

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!!

v-sathmakuri
Community Support
Community Support

Hi @Kev59 ,

 

Thank you for reaching out to Microsoft Fabric Community.

 

There’s a related issue discussed in the community forum. Reviewing that thread might help in resolving this problem.

https://community.fabric.microsoft.com/t5/Desktop/How-can-I-add-conditional-icons-with-a-compare-of-... 

 

If this post helps, then please consider Accepting as solution to help the other members find it more quickly, don't forget to give a "Kudos" – I’d truly appreciate it! 

Kev59
Helper I
Helper I

Hi again

 

So, if I well understood, there is no way to put the SVG modeling directly the calculation group items. Do you confirm?

 

BR

User defined functions are coming this which will give the flexibility for this


Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!
Deku
Super User
Super User

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.


Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

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&colon;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

 

Kev59_0-1743063627938.png

 

What am I doing wrong?

 

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.


Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

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....

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&colon;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:

Kev59_0-1742836029654.png

 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors