Forum Discussion

lovishsood1's avatar
lovishsood1
Resolver I
1 year ago
Solved

Display Data for two years based on Year filter

Hi Guys, I have this visual, and I want to display selected year and selected year - 1 data only.   Selected Year = academic_year selected from the Filter Pane. I'm not using slicers because...
  • v-tejrama's avatar
    v-tejrama
    1 year ago

    Hello again lovishsood1 ,

    I appreciate your follow-up.
    Since you’re working exclusively with the Year column and don’t have a full date table, there’s no need for time-intelligence functions. You can achieve your goal efficiently with a straightforward DAX filter, like this:

     

    ShowTwoYearsData =
    VAR SelectedYear = SELECTEDVALUE('AcademicData'[Year])
    RETURN
    CALCULATE(
       [YourMetric],
       FILTER(
           'AcademicData',
           'AcademicData'[Year] IN { SelectedYear, SelectedYear - 1 }
       )
    )

     

    This measure will accurately return results for the selected year and the previous year. You can use it directly in your visual, and it will function correctly even without a date table.

     

    If you decide to expand to months or quarters in the future, implementing a proper Date table will be beneficial. For now, this year-based approach is the most effective solution for your requirements.

    Thak you.