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
Maricel
Frequent Visitor

Is possible to filter dates in Power query using "the last 12 months"?

Hello,

 

I'm trying to create a new table which should contain the avarage price for an item based in the buying prices gotten in the last year o in the last x period.

 

The table I'm using as reference has: ID product, Prices, buying's Date.

In this table  a ID product has diferrents prices (because of the date, the supliers, etc).

 

I need to create a master table that only contains ID Product and the avarage price por that item, using only the prices gotten  in the last year to avoid mistakes or an avarage price that has no sense.

 

Is it possible to do so using power query?  How can I do that kind of table? Get the avarage prices and not including past dates?

1 ACCEPTED SOLUTION
BA_Pete
Super User
Super User

Hi @Maricel ,

 

You can use the GUI to filter last 12 complete months (i.e. not current month) like this:

BA_Pete_0-1636376619712.png

 

Which generates the code

 

Date.IsInPreviousNMonths([date], 12)

 

 

Or you can create a step like this if you want last 12 months rolling (including current month):

 

= Table.SelectRows(previousStep, each [date] >= Date.AddMonths(Date.From(DateTime.LocalNow()), -12))

 

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

2 REPLIES 2
BA_Pete
Super User
Super User

Hi @Maricel ,

 

You can use the GUI to filter last 12 complete months (i.e. not current month) like this:

BA_Pete_0-1636376619712.png

 

Which generates the code

 

Date.IsInPreviousNMonths([date], 12)

 

 

Or you can create a step like this if you want last 12 months rolling (including current month):

 

= Table.SelectRows(previousStep, each [date] >= Date.AddMonths(Date.From(DateTime.LocalNow()), -12))

 

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Greg_Deckler
Super User
Super User

@Maricel Yes, you can use Date.From (DateTime.LocalNow ()) to get the current Date and then you can just get the last year from there. 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

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!

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.

Top Solution Authors