Compare multiple date ranges to count non-overlapping dates

Huey72

New Member
Joined
Nov 6, 2019
Messages
32
Good morning everyone. I'm measuring two wait periods for a delivery cycle in days i.e., Wait 1 = the number of days between the order date and the ready to ship date, and Wait 2 = the number of days between the ready to ship date and delivery date. Within each wait period, we can have multiple date ranges where delivery is unavailable, and should be subtracted from the overall wait time. The table below outlines two sample records and the expected wait times. To note in the calculation, if there is overlap of an unavailable date with the ready to ship date, it isn't counted in Wait 1, it is counted in Wait 2.

Order DateReady to Ship DateDelivery DateDelay 1 Start DateDelay 1 End DateDelay 2 Start DateDelay 2 End DateDelay 3 Start DateDelay 3 End DateWait 1Wait 2
2019-09-012019-09-102019-09-302019-09-032019-09-302019-09-082019-09-142019-09-222019-09-23613
2019-09-062019-09-092019-09-192019-09-082019-09-112019-09-182019-09-1826

I'm looking for help with either a formula, UDF, or macros that will complete these calculations for thousands of records. Any assistance is hugely appreciated - thank you!
 
I get the same result following those steps. I haven't had any luck searching for why it's not working and if related to O365 or dynamic arrays. I'll keep looking and post back if I find something. Is there an alternative approach you might recommend that isn't array driven?
 
Upvote 0

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Do you have the dynamic array functions yet?
 
Upvote 0
Yes, I have O365 with dynamic arrays. I actually haven't used them yet, but I know I have them.
 
Upvote 0
Going back to this point,
What's interesting is if I change the Delay 1 start and end dates in the first record to 2020-09-03, the formula calculates the expected result. I don't understand why that would matter in the calculation.
What happens if array confirm the formula in a single cell and fill down, then re-type the original dates?

With dates formatted as text in the first row I also get 5 as the result, possibly you have the same problem, in which case retyping the date would most likely be correcting it to a valid format.
 
Upvote 0
In that case Jason's formula should work, without using array entry
+Fluff New.xlsm
ABCDEFGHIJK
1Order DateReady to Ship DateDelivery DateDelay 1 Start DateDelay 1 End DateDelay 2 Start DateDelay 2 End DateDelay 3 Start DateDelay 3 End DateWait 1Wait 2
201/09/201910/09/201930/09/201903/09/201903/09/201908/09/201914/09/201922/09/201923/09/2019613
306/09/201909/09/201919/09/201908/09/201911/09/201918/09/201918/09/201926
401/09/202006/09/202002/09/202002/09/20204
501/09/202006/09/202002/09/202003/09/20203
601/09/202006/09/202002/09/202004/09/20202
701/09/202006/09/202004/09/202004/09/20204
801/09/202006/09/202003/09/202004/09/20203
901/09/202006/09/202004/09/202006/09/20203
Sheet4
Cell Formulas
RangeFormula
K2:K3,J2:J9K2=NETWORKDAYS.INTL(B2,C2-1,"0000000",IFERROR(CHOOSE({1,2,3},ROW(INDIRECT($D2&":"&$E2)),ROW(INDIRECT($F2&":"&$G2)),ROW(INDIRECT($H2&":"&$I2))),0))
 
Upvote 0
In that case Jason's formula should work, without using array entry
Thanks for checking that, Fluff. I wasn't sure that it would spill correctly which was why I suggested legacy confirmation.
 
Upvote 0
That's it Jason, I had tried re-formatting the cells to dates, but didn't re-enter the values. When I re-enter the values it works as expected. Fluff, you are also right in that I don't have to commit the array, I can simply enter the formula and drag it down. I'll take a look with the full dataset to see if any any other calculations different than expected, but right now, this looks like it's working.

Thanks so much for your help - very much appreciated!!
 
Upvote 0
As you have the new functions you could also use
=NETWORKDAYS.INTL(A2,B2-1,"0000000",IFERROR(CHOOSE({1,2,3},SEQUENCE(E2-D2+1,,D2),SEQUENCE(G2-F2+1,,F2),SEQUENCE(I2-H2+1,,H2)),0))
which gets rid of the volatile Indirect function
 
Upvote 0
Solution
I have a follow-up question to Fluff's solution above using re: NETWORKDAYS.INTL(A2,B2-1,"0000000",IFERROR(CHOOSE({1,2,3},SEQUENCE(E2-D2+1,,D2),SEQUENCE(G2-F2+1,,F2),SEQUENCE(I2-H2+1,,H2)),0)).

This is working perfectly for what I needed. I'm now wondering if there's a way to count the unique days returned from the choose/sequence portion of the formula, when the dates fall within the A2 and B2 dates. Sometimes the the dates in each of the sequences overlap, so I only want to count each date once, and sometimes the dates in the sequences fall outside the date range from A2 (start date) & B2 (end date), so I also want to exclude counting any dates that fall outside of that date range.

Thanks for your help with this!
 
Upvote 0

Forum statistics

Threads
1,214,621
Messages
6,120,563
Members
448,972
Latest member
Shantanu2024

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