Forward-looking date filter by N days

NuMatt21114

New Member
Joined
Jun 2, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
I've been searching for an answer for this for days with no joy. I sure hope someone here can help.

I'm trying to filter my data based on dates. Power Query makes it easy enough to filter the Last N Days or the Next N Days. But I need to go beyond that. I need to filter by a range of dates, specifically in the future. As an example, I want to see everything that is 14-28 days in the future. PQ allows you to do Between, but you have to specify dates, not number of days, as your bookends. I've tried In The Next 28 days combined with After, but After also allows only dates. I need this to be based on # of days so that it is dynamic, updating automatically each day. I need to avoid having to input dates each time I want to refresh the data.

Thanks in advance for any help.

Matt
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
You can use the trick "between" like you described. Then simply update the M-formula.
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Dates", type date}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each [Dates] >= Date.AddDays(DateTime.Date(DateTime.LocalNow()),14) and [Dates] <= Date.AddDays(DateTime.Date(DateTime.LocalNow()),28))
in
    #"Filtered Rows"
For a simple source sample
Book1
D
2Dates
32/06/2022
43/06/2022
54/06/2022
65/06/2022
76/06/2022
87/06/2022
98/06/2022
109/06/2022
1110/06/2022
1211/06/2022
1312/06/2022
1413/06/2022
1514/06/2022
1615/06/2022
1716/06/2022
1817/06/2022
1918/06/2022
2019/06/2022
2120/06/2022
2221/06/2022
2322/06/2022
2423/06/2022
2524/06/2022
2625/06/2022
2726/06/2022
2827/06/2022
2928/06/2022
3029/06/2022
3130/06/2022
321/07/2022
332/07/2022
343/07/2022
354/07/2022
365/07/2022
376/07/2022
387/07/2022
398/07/2022
409/07/2022
4110/07/2022
4211/07/2022
4312/07/2022
4413/07/2022
4514/07/2022
4615/07/2022
4716/07/2022
4817/07/2022
4918/07/2022
5019/07/2022
5120/07/2022
5221/07/2022
5322/07/2022
5423/07/2022
5524/07/2022
5625/07/2022
5726/07/2022
5827/07/2022
5928/07/2022
6029/07/2022
6130/07/2022
6231/07/2022
631/08/2022
642/08/2022
653/08/2022
664/08/2022
675/08/2022
686/08/2022
697/08/2022
708/08/2022
719/08/2022
7210/08/2022
7311/08/2022
7412/08/2022
7513/08/2022
7614/08/2022
7715/08/2022
7816/08/2022
7917/08/2022
8018/08/2022
8119/08/2022
8220/08/2022
8321/08/2022
8422/08/2022
8523/08/2022
8624/08/2022
8725/08/2022
8826/08/2022
8927/08/2022
9028/08/2022
9129/08/2022
9230/08/2022
9331/08/2022
941/09/2022
952/09/2022
963/09/2022
974/09/2022
985/09/2022
996/09/2022
1007/09/2022
1018/09/2022
1029/09/2022
Sheet1
 
Upvote 0
Solution
G.,

Thanks so much for that. I hadn't been able to nail down the M language necessary, but this worked perfectly. Exactly what I needed!

Matt

You can use the trick "between" like you described. Then simply update the M-formula.
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Dates", type date}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each [Dates] >= Date.AddDays(DateTime.Date(DateTime.LocalNow()),14) and [Dates] <= Date.AddDays(DateTime.Date(DateTime.LocalNow()),28))
in
    #"Filtered Rows"

[/QUOTE]
 
Upvote 0
Thanks for the feedback. Glad to help.
 
Upvote 0

Forum statistics

Threads
1,223,663
Messages
6,173,650
Members
452,525
Latest member
DPOLKADOT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top