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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
villa1980
Resolver I
Resolver I

filter previous 2 years power query help

Hi all,

 

 I have a table that is currently looking at data from 2021 in column TRANSACTION_DATE.

 I would like to filter this in Power Query M to Transaction_Date is >= 2 years previous (which will change next year to 2024, 2025, 2026 etc), so would see 2023, 2024 and 2025 this year.

 Cannot figure out how to do this within the applied steps formula.


 Your help would be appreciated.

 Many Thanks

Alex

2 ACCEPTED SOLUTIONS
villa1980
Resolver I
Resolver I

Managed to find the solution....

 

Table.SelectRows(#"Changed Type", each [TRANSACTION_DATE] >= DateTime.Date(Date.AddYears(DateTime.LocalNow(),-2)))

View solution in original post

Bibiano_Geraldo
Super User
Super User

Hi @villa1980 ,

In power query, please add a new custom column using this M code to get the year:

Date.Year([TRANSACTION_DATE])

 Now in APPLIED STEPS, right click in last step and inser step after with this M code:

= Table.SelectRows(#"Added Custom", each [Custom] >= Date.Year(DateTime.LocalNow()) - 2)

This will dynamically adjust each year and include data for the last two years plus the current year.

 

 

Is this post help you? Please consider to:

Accept as Solution!
Give a Kudo
Follow me on Linkedin

View solution in original post

2 REPLIES 2
Bibiano_Geraldo
Super User
Super User

Hi @villa1980 ,

In power query, please add a new custom column using this M code to get the year:

Date.Year([TRANSACTION_DATE])

 Now in APPLIED STEPS, right click in last step and inser step after with this M code:

= Table.SelectRows(#"Added Custom", each [Custom] >= Date.Year(DateTime.LocalNow()) - 2)

This will dynamically adjust each year and include data for the last two years plus the current year.

 

 

Is this post help you? Please consider to:

Accept as Solution!
Give a Kudo
Follow me on Linkedin

villa1980
Resolver I
Resolver I

Managed to find the solution....

 

Table.SelectRows(#"Changed Type", each [TRANSACTION_DATE] >= DateTime.Date(Date.AddYears(DateTime.LocalNow(),-2)))

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! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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