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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
hemakrishnamoor
Regular Visitor

Help with 5 yr historical data

I have a situation where I am using a published semantic model and so no rights to create a table or add another column. When the user selects a year (there is no date table in this model. Just the year of the date column that I need to show in the report), I need to show data from the year chosen going back 5 years. aas the filter and data are coming from the same field, no matter how much I try in DAX to removefilter and retriecing 5 years data and adding new filter, it either shows all years and not stopping at -5 or shows only the year selected. Is there a way to do this?

 

12 REPLIES 12
v-moharafi-msft
Community Support
Community Support

Hi  @hemakrishnamoor  ,


We wanted to check if your question has been resolved or if you are still facing any confusion feel free to reach out. Providing an update can be beneficial for others who might be experiencing similar challenges.

 

Best Regards,

Abdul Rafi

Hi,

 

I have solved it in a different way as my hands were tied with a strict semantic model with no ways of creating a date table or adding a column. Instead of pulling all the 5 years worth historical data together, I had individual measures going after year -1, year -2, etc and solved it. Thank you all for the reply and suggestions. Truly appreciate it.

v-moharafi-msft
Community Support
Community Support

Hi  @hemakrishnamoor ,


Thank you for reaching out to Microsoft Fabric Community and Thanks to @lbendlin   , @danextian  and @cengizhanarslan   for Sharing valuable insights.


Just wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. 

 

 Best Regards,

Abdul Rafi.

cengizhanarslan
Super User
Super User

Step 1) Create a disconnected year slicer table

YearSelector =
DISTINCT (
    SELECTCOLUMNS (
        ALLNOBLANKROW ( FactTable[YearColumn] ),
        "Selected Year", FactTable[YearColumn]
    )
)

 

Step 2) Use this as your year slicer instead of the original year column

Remove the original year from the slicer and use YearSelector[Selected Year] instead.

 

Step 3) Create a measure that filters the data to the 5-year window

Value Last 5 Years =
VAR _SelectedYear =
    SELECTEDVALUE ( YearSelector[Selected Year] )
VAR _StartYear = _SelectedYear - 4
RETURN
    CALCULATE (
        [Your Base Measure],
        REMOVEFILTERS ( FactTable[YearColumn] ),
        FactTable[YearColumn] >= _StartYear,
        FactTable[YearColumn] <= _SelectedYear
    )

 

Step 4) Control which years appear as rows in your visual

Add a visual-level filter using this helper measure:

Is In 5 Year Window =
VAR _SelectedYear =
    SELECTEDVALUE ( YearSelector[Selected Year] )
RETURN
    IF (
        MAX ( FactTable[YearColumn] ) >= _SelectedYear - 4
            && MAX ( FactTable[YearColumn] ) <= _SelectedYear,
        1,
        BLANK ()
    )

Add Is In 5 Year Window to Filters on this visual → set to is 1.

_________________________________________________________
If this helped, ✓ Mark as Solution | Kudos appreciated
Connect on LinkedIn | Follow on Medium
AI-assisted tools are used solely for wording support. All conclusions are independently reviewed.

If I create the YearSelector, I cannot use it in a slicer because it is a measure, correct? How do I work around that?

 

 

Hi @hemakrishnamoor ,

 

Thank you for your patience.

I recreated the same scenario using a slicer and matrix with the same Year field to better understand the behavior.

vmoharafimsft_0-1778235717244.png

 

vmoharafimsft_1-1778235717246.png

 

What you’re experiencing is expected due to how filter context works in Power BI. When the slicer and the visual both use the same Year field, the slicer removes all other years before the measure is evaluated, so DAX (even with REMOVEFILTERS) cannot bring those rows back.

 

The standard approach for this requirement is to use a disconnected Year table so the slicer logic is separated from the reporting data. I tested this approach in a sample model, and the rolling 5-year logic worked correctly once the slicer was disconnected from the main table. I’m sharing screenshots from the recreated setup for reference.

 

Also, YearSelector should be created as a calculated table, not a measure. Once created as a table, its Year column can be used directly in the slicer.

However, since you’re working with a published semantic model and  don’t have permission to modify the model, implementing this directly in the current report may not be possible.

Few Workarounds possible in this scenario :

  • Requesting the dataset owner to add a proper Date table or disconnected Year table in the semantic model,
  • Enabling a local/composite model using “Make changes to this model” (if permitted in your environment)

For details, see the documentation:

https://learn.microsoft.com/en-us/power-bi/transform-model/desktop-composite-models

Best Regards,
Abdul Rafi

 

danextian
Super User
Super User

Hi @hemakrishnamoor 

Are you able to connect to the semantic model via direct query. As other users have already suggested, the only solution is to use a disconnected table which cannot be done with live  connection as this requires modifying the model. A filter from a related or the same table will show only what's been selected.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
krishnakanth240
Resident Rockstar
Resident Rockstar

Hi @hemakrishnamoor 

Since you can not modify the model, workaround is to use a disconnected table for Year

 

Year Slicer = DISTINCT('Table'[Year])

 

Then

5Y Data =

VAR SelectedYear = SELECTEDVALUE('Year Slicer'[Year])

RETURN

CALCULATE([Your Measure],

FILTER(ALL('Table'[Year]),

'Table'[Year] <= SelectedYear &&

'Table'[Year] > SelectedYear - 5))

Slicer comes from disconnected table. Measure applies custom filter logic for last 5 years. Avoids conflict with existing filter context

This does not work for me either. If possible, please send me a sample workbook showing this. 

lbendlin
Super User
Super User

Your filter needs to be fed from a disconnected table, cannot be fed directly from the calendar dimension table.

 

 

I just have the one table that has the data in it and the column record create date, which has a hierarchy. The year of that is what the user picks  for the report. The matrix below shows yr and yr -5 from the same table. Is that possible?

The year of that is what the user picks  for the report. The matrix below shows yr and yr -5 from the same table. Is that possible?

No.  You need a disconnected table. Your semantic model should also have a calendar table.

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.