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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
dgdgdg122db
Helper II
Helper II

SVG line chart show last 12 months trend regardless of year moth slicer

Hello there,

I'd like to adjust the SVG data to display only the trend for the past 12 months, disregarding any date slicer selections from the report page. Currently, when I select the year-month slicer, the SVG line also filters accordingly, which I don't want.

Thank you 


SVG=

VAR XMinDate = MIN(sales[posting_date])
VAR XMaxDate = MAX(sales[posting_date])
VAR YMinValue = MINX(Values(Dates[start of month]),CALCULATE([Revenue]))
VAR YMaxValue = MAXX(Values(Dates[start of month]),CALCULATE([Revenue]))
 
VAR SparklineTable = ADDCOLUMNS(
    SUMMARIZE(sales,Dates[start of month]),
        "X",INT(580 * DIVIDE(Dates[start of month] - XMinDate, XMaxDate - XMinDate)),
        "Y",INT(100 * DIVIDE([Reveune] - YMinValue,YMaxValue - YMinValue)))
 
VAR Lines = CONCATENATEX(SparklineTable,[X] & "," & 100-[Y]," ", Dates[start of month])
 
VAR SVGImageURL =
   "data:image/svg+xml;utf8," &
    "<svg xmlns='http://www.w3.org/2000/svg' x='0px' y='0px' viewBox='0 0 600 120'>"  &
     "<polyline fill='%231A0033' fill-opacity='0.1' stroke='%231A0033' stroke-width='3' points=' 0 600 " & Lines & " 600,120'/></svg>"

RETURN SVGImageURL
3 REPLIES 3
dgdgdg122db
Helper II
Helper II

Thank you Rena, it does not work, the svg is still filtered by the report level slicer. Normally I can use ALL/ Allselecetd/ removefilters to disregard any filter coming from the outside of my current measure. but I am struggling to do it in the SVG.  The goal is to just show the last 12 months trend , igroning any dates selected from the report page.  for example. if the year month slicer on the report page is selected:  Mar-2024, the SVG should still show the last 12 months trend, not Mar-2024 data

Anonymous
Not applicable

Hi @dgdgdg122db ,

Please try the following formula:

SVG =
VAR CurrentDate =
    TODAY ()
VAR XMinDate =
    EOMONTH ( CurrentDate, -13 ) + 1 // Start of the month 12 months ago
VAR XMaxDate =
    EOMONTH ( CurrentDate, -1 ) + 1 // Start of the current month
VAR YMinValue =
    CALCULATE (
        MIN ( sales[Revenue] ),
        FILTER (
            ALL ( sales ),
            sales[posting_date] >= XMinDate
                && sales[posting_date] < XMaxDate
        )
    )
VAR YMaxValue =
    CALCULATE (
        MAX ( sales[Revenue] ),
        FILTER (
            ALL ( sales ),
            sales[posting_date] >= XMinDate
                && sales[posting_date] < XMaxDate
        )
    )
VAR SparklineTable =
    ADDCOLUMNS (
        SUMMARIZE ( sales, sales[posting_date] ),
        "X",
            INT ( 580 * DIVIDE ( sales[posting_date] - XMinDate, XMaxDate - XMinDate ) ),
        "Y",
            INT ( 100 * DIVIDE ( [Revenue] - YMinValue, YMaxValue - YMinValue ) )
    )
VAR Lines =
    CONCATENATEX ( SparklineTable, [X] & "," & 100 - [Y], " ", sales[posting_date] )
VAR SVGImageURL = "data&colon;image/svg+xml;utf8," & "<svg xmlns='http://www.w3.org/2000/svg' x='0px' y='0px' viewBox='0 0 600 120'>" & "<polyline fill='%231A0033' fill-opacity='0.1' stroke='%231A0033' stroke-width='3' points=' 0 600 " & Lines & " 600,120'/></svg>"
RETURN
    SVGImageURL

Best Regards

Anonymous
Not applicable

Hi @dgdgdg122db ,

Please update the formula as below and check if it can return the expected result...

SVG =
VAR XMinDate =
    MIN ( sales[posting_date] )
VAR XMaxDate =
    MAX ( sales[posting_date] )
VAR YMinValue =
    MINX ( VALUES ( Dates[start of month] ), CALCULATE ( [Revenue] ) )
VAR YMaxValue =
    MAXX ( VALUES ( Dates[start of month] ), CALCULATE ( [Revenue] ) )
VAR SparklineTable =
    ADDCOLUMNS (
        SUMMARIZE (
            FILTER ( sales, sales[posting_date] >= TODAY () - 365 ),
            Dates[start of month]
        ),
        "X",
            INT ( 580 * DIVIDE ( Dates[start of month] - XMinDate, XMaxDate - XMinDate ) ),
        "Y",
            INT ( 100 * DIVIDE ( [Revenue] - YMinValue, YMaxValue - YMinValue ) )
    )
VAR Lines =
    CONCATENATEX (
        SparklineTable,
        [X] & "," & 100 - [Y],
        " ",
        Dates[start of month]
    )
VAR SVGImageURL = "data&colon;image/svg+xml;utf8," & "<svg xmlns='http://www.w3.org/2000/svg' x='0px' y='0px' viewBox='0 0 600 120'>" & "<polyline fill='%231A0033' fill-opacity='0.1' stroke='%231A0033' stroke-width='3' points=' 0 600 " & Lines & " 600,120'/></svg>"
RETURN
    SVGImageURL

Best Regards

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

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.