Forum Discussion

F_Reh's avatar
F_Reh
Icon for Post Patron rankPost Patron
5 months ago
Solved

Dynamically adjusting Graph's Legend to compare past two years

Good Afternoon,   I have a graph as this:     Currently, I am using the Filter pane to manually restrict the data to 2024 & 2025 only. The Y-Axis is essentially using a measure for Total M...
  • johnt75's avatar
    5 months ago

    Add a column onto your date table, you could add a calculated column in DAX like

    Current or Previous Year =
    'Date'[Year] = YEAR ( TODAY () ) || 'Date'[Year] = YEAR ( TODAY () ) - 1
    

    or could do the same thing in Power Query or SQL.

    Use that column as a filter on the chart visual.

  • cengizhanarslan's avatar
    5 months ago

    Create a calculated column in your Date table for relative year label

    Is Rolling 2 Years =
    IF (
        'Date'[Year] >= YEAR ( TODAY () ) - 1
            && 'Date'[Year] <= YEAR ( TODAY () ),
        1,
        0
    )

     

    Then in the visual, add Is Rolling 2 Years to Filters on this visual and set it to is 1. Done. Updates automatically every year with no maintenance needed.