Power Query filter date from today minus ? days to today

Viewed 9769

I'm just learning Power Query and trying to figure out how modify a filter to return data within a dynamic date range. E.g. from Today - 60 days to Today Here's the code, any help much appreciated.

= Table.SelectRows(#"Changed Type", each [Start] >= Date.AddDays(DateTime.Date(DateTime.LocalNow())-60) and [Start] <= DateTime.Date(DateTime.LocalNow()))
2 Answers

You can do that also in UI.

If your column if type date: enter image description here

enter image description here

Then when you look into Advanced Editor (or formula bar) you will see that Power Query has dedicated function for that:

#"Filtered Rows" = Table.SelectRows(#"Changed Type", each Date.IsInPreviousNDays([Column1], 60))
= Table.SelectRows(#"Changed Type", each [Start] >= Date.AddDays(Date.From(DateTime.LocalNow()),-60) and [Start] <= Date.From(DateTime.LocalNow()))
Related