Forum Discussion

Narukkp's avatar
Narukkp
Helper V
5 years ago
Solved

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 ...
  • edhans's avatar
    5 years ago

    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.