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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
adityah
Frequent Visitor

Display data for past 3 years from selected date in slicer

I'm trying to create a date filter which will filter past 3 years data based on selection in a PBI matrix. The columns are the years. Below is a screenshot of how the marix looks like:

 

adityah_0-1732777637100.png

 

So if I select 2024 in date filter, it should display 2024, 2023 and 2022. if I select 2023, it should display 2023,2022, 2021. I realise there are previous posts similar to this, but they dont seem to work for matrix since I need to put Year in columns instead of values (previous results suggest creating a measure, which cannot go into pbi matrix column. only in values)

 

I have a separate date table which is related to all the other tables

 

5 REPLIES 5
Anonymous
Not applicable

Hi @adityah , hello All, thank you for your prompt reply!

Create a new calculated Date table as the slicer, then create a new measure as shown below:

past 3 years = 
VAR data_year = YEAR(SELECTEDVALUE('FactTable'[date]))

VAR slicer_year = SELECTEDVALUE('DuplicateDate'[Date].[Year])
RETURN
IF(data_year<=slicer_year && data_year>slicer_year-3,
    1,
    0
)

Then add the measure to visual filter like this:

vyajiewanmsft_0-1733131366736.png
Result for your reference:

vyajiewanmsft_1-1733131441793.png

 

Best regards,

Joyce

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Kedar_Pande
Super User
Super User

@adityah 

Create a new measure

Filtered Endorsements = 
VAR SelectedYear = SELECTEDVALUE(DateTable[Year])
RETURN
CALCULATE(
SUM('YourDataTable'[Endorsements]),
FILTER(
ALL(DateTable),
DateTable[Year] >= SelectedYear - 2 && DateTable[Year] <= SelectedYear
)
)

💌 If this helped, a Kudos 👍 or Solution mark ✔️would be great! 🎉
Cheers,
Kedar
Connect on LinkedIn

This wont work. since I need to bring it in columns. You cannot bring a metric into matrix columns

hi @adityah ,

To achieve this, follow below process
1. create a separate calender dimention table covering all the dates in your dataset. dont create any relationship. 

2. use this date in your slicer

3. now you need to create three different measures for "new", "endrosment","GWP" as per below syntax.

 

measure = 
var start_year_Base =year( selectedvalue(dim_calender[date])]) - 2

var end_year_Base =year( selectedvalue(dim_calender[date])])
return
calculate (sum(table,[GWP]),year(table[date])>=start_year_base,year(table[date])<=end_year_base)

This should work. please share sample data if it fails.

 



Regards
Rupak
FOLLOW ME : https://www.linkedin.com/in/rupaksar/
johnt75
Super User
Super User

Have a look at https://www.sqlbi.com/articles/show-previous-6-months-of-data-from-single-slicer-selection/ . By putting 'Previous Dates'[Year] in the matrix you should get the behaviour you are looking for.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.