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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Narukkp
Helper V
Helper V

M-Query previous month filter is not working like SQL Database for Previous 2 months

Hi Team,
I have last 2 months data based on current day but M-Query previous month filter is not working like SQL Database for Previous 2 months and it is giving the data from Aug1st2020 instead of Aug15th2020.

Could you please let me know how to restrict the exact last 2 months data(From Aug15th2020) based on current day.

 

 

 

 

 

1 ACCEPTED SOLUTION
edhans
Community Champion
Community Champion

Use Date.AddMonths. See below:

edhans_0-1602776058958.png

Date.AddMonths([Date], -2)

That will move the date exactly 2 months back where possible. Notice how I moved Oct 31 1 month ago. There's no September 31, so he moved it to September 30 in that case.

To use it as a filter using today's date, you can use this:

= Table.SelectRows(#"Added Custom1", each [Two Months back] >= Date.AddMonths(DateTime.Date(DateTime.LocalNow()), -2))

That will make it all August 15, 2020 and later.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

4 REPLIES 4
edhans
Community Champion
Community Champion

Use Date.AddMonths. See below:

edhans_0-1602776058958.png

Date.AddMonths([Date], -2)

That will move the date exactly 2 months back where possible. Notice how I moved Oct 31 1 month ago. There's no September 31, so he moved it to September 30 in that case.

To use it as a filter using today's date, you can use this:

= Table.SelectRows(#"Added Custom1", each [Two Months back] >= Date.AddMonths(DateTime.Date(DateTime.LocalNow()), -2))

That will make it all August 15, 2020 and later.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Thank you so much it is working ...

Hi, @Narukkp 

Could you please tell me whether your problem has been solved?
If it is,  please mark the helpful replies or add your reply as Answered to close this thread.
If you haven't, please share  more details.

 

Best Regards,
Community Support Team _ Eason

Thanks for your reply , but i required the two months back data based on table column i.e i have a table called sales trans and it is having the Invoice Date , so i reuqired the last 2 months invoice dates.

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors
Top Kudoed Authors