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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

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
v-yajiewan-msft
Community Support
Community Support

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
Community Champion
Community Champion

@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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.