Forum Discussion

hwaheed629's avatar
hwaheed629
Frequent Visitor
9 months ago
Solved

Horizontal Scale per metric in a Matrix

Hello, 

I have been tasked with creating a horizontal scale for 20 metrics in a matrix visual that also displays the actual and target for that month. This horizontal scale should also show an arrow to show the actual value and target line and where it falls on that 0-4 scale. The 0-4 is consistent for all but will have each threshold value under the area. The data structure is setup where I have the actual, target, and threshold values from 0-4. I tried doing it with SVG using the code below, however its not rendering into the full cell (attached image). Is there a way to fix this or build a visual that would give me the same result? 

Needs to look like this: 

PBI is rendering this using the SVG code below: 

VAR CalcLevel = MAX(Table[CalculatedLevel])
RETURN
IF(
    NOT ISBLANK(CalcLevel) && CalcLevel >= 0 && CalcLevel <= 4,

    VAR Actual = [ActualYTD]
    VAR Target = [TargetYTD]
    VAR MinScale = 0
    VAR MaxScale = 4

    -- Layout relative to cell with padding
    VAR RowHeight = 100
    VAR Padding = 13
    VAR BoxCount = 5
    VAR BoxW = 100 / BoxCount            -- width as % of total width
    VAR BoxH = RowHeight - Padding       -- height relative to row height
    VAR BoxY = Padding / 2               -- top padding

    -- Positions as percentage of width
    VAR ActualPos = DIVIDE(Actual - MinScale, MaxScale - MinScale) * 100
    VAR TargetPos = DIVIDE(Target - MinScale, MaxScale - MinScale) * 100

    RETURN
        "data&colon;image/svg+xml;utf8," &
        "<svg width='100%' height='100%' viewBox='0 0 100 " & RowHeight & "' xmlns='http://www.w3.org/2000/svg'>" &

        /* Draw 5 boxes */
        CONCATENATEX(
            GENERATESERIES(0, BoxCount-1, 1),
            "<rect x='" & ([Value]*BoxW) & "' y='" & BoxY &
            "' width='" & BoxW & "' height='" & BoxH &
            "' fill='white' stroke='black' stroke-width='0.5'/>",
            ""
        ) &

        /* Labels 0–4 centered in boxes */
        CONCATENATEX(
            GENERATESERIES(0, BoxCount-1, 1),
            "<text x='" & ([Value]*BoxW + BoxW/2) & "' y='" & (BoxY + BoxH/2) &
            "' font-size='8' text-anchor='middle' alignment-baseline='middle'>" & [Value] & "</text>",
            ""
        ) &

        /* Actual arrow */
        "<polygon points='" &
            ActualPos & ",5 " & ActualPos-2 & "," & BoxY & " " & ActualPos+2 & "," & BoxY & "' fill='blue'/>" &

        /* Actual label */
        "<text x='" & ActualPos & "' y='3' font-size='6' text-anchor='middle'>Actual: " &
            FORMAT(Actual, "0.00") & "</text>" &

        /* Target line */
        "<line x1='" & TargetPos & "' y1='" & BoxY &
            "' x2='" & TargetPos & "' y2='" & BoxY+BoxH & "' stroke='red' stroke-width='0.5'/>" &

        /* Target label */
        "<text x='" & TargetPos & "' y='" & BoxY+BoxH+5 & "' font-size='6' text-anchor='middle'>Target: " &
            FORMAT(Target, "0.00") & "</text>" &

        "</svg>",
    BLANK()
)
  • Hi hwaheed629,

    We would like to confirm if our super user answer resolves your query or if you need further help. If you still have any questions or need more support, please feel free to let us know. We are happy to help you.

     

     

     

    Thank you for your patience and look forward to hearing from you.
    Best Regards,
    Prashanth Are
    MS Fabric community support

5 Replies

    • hwaheed629's avatar
      hwaheed629
      Frequent Visitor

      No. I need to add this to a matrix that has the metric name, actual and target listed out in the other columns. Moreover, I would need the 0-4 scale in the horizontal chart has to be consistent for all metrics. Each metric has their own format as well (#,$,%) which is controlled by a format field. Unless there is a way to make this possible with the bullet graph, but I am not seeing as an option to add to a matrix. 

  • v-prasare's avatar
    v-prasare
    Icon for Community Support rankCommunity Support

    Hi hwaheed629,

    We would like to confirm if our super user answer resolves your query or if you need further help. If you still have any questions or need more support, please feel free to let us know. We are happy to help you.

     

     

     

    Thank you for your patience and look forward to hearing from you.
    Best Regards,
    Prashanth Are
    MS Fabric community support

  • v-prasare's avatar
    v-prasare
    Icon for Community Support rankCommunity Support

    Hi hwaheed629,

    We would like to confirm if our super user answer resolves your query or if you need further help. If you still have any questions or need more support, please feel free to let us know. We are happy to help you.

     

     

     

    Thank you for your patience and look forward to hearing from you.
    Best Regards,
    Prashanth Are
    MS Fabric community support