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
ramshoney1225
Helper V
Helper V

How to give default filters for 2 years , Dynamic filter of 2 years ?

Hi 

 

I have a requirment i have 10 years of data 2012 to 2021 data but my requreiment is my year filter should be dynamic to last two years. 

 

Now it should be default to 2020 and 2021

after getting 2022 year, my default filter should to 2021 and 2022

 

How to do this dynamically for filtering the page for two last years dynamically?

 

Thanks,

Ramss

1 ACCEPTED SOLUTION
v-xiaotang
Community Support
Community Support

Hi @ramshoney1225 

Supposing you have a date table and a fact table,

vxiaotang_0-1628242514063.png

then create the measure and put the measure into Filters 

 

Measure = 
    var _Isfiltered=ISFILTERED(dateTable[Year])
    var _maxYearinData=YEAR(CALCULATE(MAX(factTable[Date]),ALL(factTable)))
    var _selectedYear=MIN(dateTable[Year])
return 
    IF(_Isfiltered,IF(YEAR(MIN(factTable[Date]))<=_selectedYear&&YEAR(MIN(factTable[Date]))>=_selectedYear-1,1,0),IF(YEAR(MIN(factTable[Date]))<=_maxYearinData&&YEAR(MIN(factTable[Date]))>=_maxYearinData-1,1,0))

 

vxiaotang_1-1628242609105.png

result

vxiaotang_2-1628242765073.gif

 

 

 

Best Regards,

Community Support Team _Tang

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

View solution in original post

2 REPLIES 2
v-xiaotang
Community Support
Community Support

Hi @ramshoney1225 

Supposing you have a date table and a fact table,

vxiaotang_0-1628242514063.png

then create the measure and put the measure into Filters 

 

Measure = 
    var _Isfiltered=ISFILTERED(dateTable[Year])
    var _maxYearinData=YEAR(CALCULATE(MAX(factTable[Date]),ALL(factTable)))
    var _selectedYear=MIN(dateTable[Year])
return 
    IF(_Isfiltered,IF(YEAR(MIN(factTable[Date]))<=_selectedYear&&YEAR(MIN(factTable[Date]))>=_selectedYear-1,1,0),IF(YEAR(MIN(factTable[Date]))<=_maxYearinData&&YEAR(MIN(factTable[Date]))>=_maxYearinData-1,1,0))

 

vxiaotang_1-1628242609105.png

result

vxiaotang_2-1628242765073.gif

 

 

 

Best Regards,

Community Support Team _Tang

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

amitchandak
Super User
Super User

@ramshoney1225 , You need to create this type of column in your year/date table and use that

 

if([Year] >= year(Today())-1 && [Year] <= year(Today()) , "Last two year" , [Year] )

 

Default Date Today/ This Month / This Year: https://www.youtube.com/watch?v=hfn05preQYA&list=PLPaNVDMhUXGaaqV92SBD5X2hk3TMNlHhb&index=35

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
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.