cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Gordon2 Member
Member

filter last n months in query editor

I would like to limit my dataset to return only last two months availabe. 

As my last month in a dataset is not the current month. For instance:

-current month is March 2019

-the latest month in the dataset is December 2018

So I would like to filter Dec 2018 and Nov 2018...

But I would like it to be dynamic. I mean, whenever my data grows and a new month be availabe, I would like to have always last 2 month from the latest one in the dataste.

Hope it is clear.

 

My date column looks like this:

Capture.PNG

and at this moment contains dates from Dec 2016 to Dec 2018

 

Thanks in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Support Team
Community Support Team

Re: filter last n months in query editor

Hi @Gordon2 ,

 

Please try this query below. In my test file, I have the date from 2018/1/1 to 2018/12/31.

 

=Table.SelectRows(#"Changed Type", each [Date] > Date.AddMonths(List.Max(#"Changed Type"[Date]),-2))

Here is the output.

 

Capture.PNG

 

More details, please refer to my attachement.

 

Reference, you also could have a look at this similar thread.

 

Best  Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
Highlighted
Community Support Team
Community Support Team

Re: filter last n months in query editor

Hi @Gordon2 ,

 

Please try this query below. In my test file, I have the date from 2018/1/1 to 2018/12/31.

 

=Table.SelectRows(#"Changed Type", each [Date] > Date.AddMonths(List.Max(#"Changed Type"[Date]),-2))

Here is the output.

 

Capture.PNG

 

More details, please refer to my attachement.

 

Reference, you also could have a look at this similar thread.

 

Best  Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Gordon2 Member
Member

Re: filter last n months in query editor

The M is working, thanks Cherry!

Helpful resources

Announcements
Can You Solve These Challenge

Challenge: Can You Solve These?

Find out how to participate in the first Power BI 'Can You Solve These?' challenge.

Community News & Announcements

Community News & Announcements

Get your latest community news and announcements.

Virtual Launch Event

Microsoft Business Applications October Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

Community Kudopalooza

Win Power BI Swag with Community Kudopalooza!

Each week, complete activities and be qualified in the drawing for cool Power BI Swag.

Users Online
Currently online: 80 members 1,298 guests
Please welcome our newest community members: