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
Anonymous
Not applicable

Is it possible to include only a selected year and 4 years in the past?

Would it be possible to have a filter on a visualization which allows you to select a year and includes data for the last 4 years? Like for example, if I select 2016, the visualization will include data for 2016, 2015, 2014 and 2013.

2 REPLIES 2
v-haibl-msft
Microsoft Employee
Microsoft Employee

@Anonymous

 

Not sure what does the final visual chart like. But you can try with following steps to see if it is you expected.

 

  1. Create a calendar table if not exists and add two columns of YearMonth and Year. Create relationship with the fact table.
    YearMonth = 
    YEAR ( 'Calendar'[Date] ) * 100
    + MONTH ( 'Calendar'[Date] )
    Year = 
    YEAR ( 'Calendar'[Date] )
  2. Create a Year table with following formula. It will list the distinct years. Do not create relationship with other tables.
    Year = 
    VALUES ( 'Calendar'[Year] )
  3. Create a Year column in the fact table.
    Year = 
    YEAR ( Table1[Date] )
  4. Create a measure to calculate something like total sales.
    TotalSales = 
    VAR LastDay =
        DATE ( MAX ( 'Year'[Year] ), 12, 31 )
    VAR FirstDay =
        EDATE ( LastDay, -48 )
    VAR TotalSales =
        SUM ( Table1[Sales] )
    RETURN
        IF (
            MIN ( 'Calendar'[Date] ) < FirstDay,
            BLANK (),
            IF ( MIN ( 'Calendar'[Date] ) > LastDay, BLANK (), TotalSales )
    )
  5. Use the column chart and slicer (use the 'Year'[Year] column) to show the result.
    Is it possible to include only a selected year and 4 years in the past_2.jpg

Best Regards,

Herbert

Meagan
Most Valuable Professional
Most Valuable Professional

This is possible.  For example, if I have sales data and I want to choose a year and see the last four years, my calculation might be. You just have to make use of CALCULATE and possibley FILTER. This also depends on whether you want just whole years or if you mean rolling 12 month periods. If you mean rolling periods, you would have to alter your formula and you could probably use DATESBETWEEN instead of the FILTER function in the calculation below.

  

Last 4 years = CALCULATE(Sum('FactInternetSales'[SalesAmount]), Filter(All('DimDate'),'DimDate'[CalendarYear] <= Max('DimDate'[CalendarYear]) && 'DimDate'[CalendarYear] > MAX('DimDate'[CalendarYear]) - 4))

 

 

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