4

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()))
ZygD
  • 22,092
  • 39
  • 79
  • 102
Kholt69
  • 43
  • 1
  • 1
  • 4

2 Answers2

3
= Table.SelectRows(#"Changed Type", each [Start] >= Date.AddDays(Date.From(DateTime.LocalNow()),-60) and [Start] <= Date.From(DateTime.LocalNow()))
ZygD
  • 22,092
  • 39
  • 79
  • 102
  • Thx ZygD, just what I need, tweaked it to look at a forward date range as well and works a treat. Appreciate the help – Kholt69 Jan 05 '21 at 13:18
3

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))
Michal Palko
  • 601
  • 1
  • 4
  • 14