Unexpected flaw in WORKDAY formula to calculate date

EdNerd

Active Member
Joined
May 19, 2011
Messages
456
We work with data reports. Depending on the date the data is generated and the intended routing of the report, each report has milestone dates as it runs through the editing and QA processes. I created a spreadsheet which we all use to calculate our due dates at these various milestones. It's been working fine - until someone did something I never expected them to do!!

The formula in question is (for row 47):
=IF(ISERR(MATCH($F47,Class,0)),0,IF($D47>0,WORKDAY($D47,HLOOKUP($F47,WhenDue,2,FALSE),Holidays),""))

The start date is in D47
I use three named ranges of values to assist in calculating the milestone due dates:
-- Class gives us the intended routing: This value is in F47
-- WhenDue gives us the number of days to the milestone
-- Holidays is a list of dates that are removed from the date calculations for various company reasons. For instance, if there's a training day, we're not expected to move the report forward on that day, so we get a "freebie". If the result occurs on a Monday, and the normal routing would be due on Thursday, but we have a "freebie" on Tuesday, then routing is pushed back to Friday.

And here's where the "unexpected flaw" comes in. The formula works great -- AND THEN ....
We had data generated on a "freebie" day. The expectation was that, because this specific date is included in the Holidays range listing, it would be ignored and the due date pushed back. To use the example above:
If the result occurred on Monday, with a "freebie" on Tuesday, routing shows as Friday as expected.
If the result occurred on the Tuesday freebie day, we would ~~expect~~ the routing milestone to push to Monday (since WORKDAY excludes weekends).
Instead, we see the milestone on Friday.

So it seems like I need a way to detect if the date in D7 is included in the Holidays table, and if so increment the date until it's valid. Or something like that?? What would be the easiest way to adjust this to give the result we need?
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
I don't see the problem. WORKDAY does not "count" the start date. A Monday start date in D47 with a freebie day the next day (Tue), and let's say a 3-day due date, would give an action period of Wed, Thu, Fri...so the due date would be Fri. Similarly, a Tuesday start date in D47 (which happens to fall on the freebie date) still doesn't count...that's day 0...so a 3-day due date would still give an action period of Wed, Thu, Fri...the due date is still Friday. The start date would need to be Wed in order for a 3-day action period to jump to the following Monday. Am I missing something?
 
Upvote 0
I don't see the problem. WORKDAY does not "count" the start date. A Monday start date in D47 with a freebie day the next day (Tue), and let's say a 3-day due date, would give an action period of Wed, Thu, Fri...so the due date would be Fri. Similarly, a Tuesday start date in D47 (which happens to fall on the freebie date) still doesn't count...that's day 0...so a 3-day due date would still give an action period of Wed, Thu, Fri...the due date is still Friday. The start date would need to be Wed in order for a 3-day action period to jump to the following Monday. Am I missing something?
That is all correct. The issue is not with WORKDAY. The problem is in my entire formula, which fails to account for a start date on a freebie day. I'm wondering if there's any good way to get around this. Perhaps I need a macro to check the start date: if it exists in the Holidays range, then increment the date until it isn't?? Or would it be easier to adjust the formula??
 
Upvote 0
I see now...thank you. Yes, how 'bout using:
Excel Formula:
=WORKDAY(C47-1,1,Holidays)
where C47 is the "data generated" date you mentioned. We go back 1 day before and then look for the next actual workday while recognizing Holidays and weekends...so we'll jump forward to the original day if it's not a holiday or weekend day...or jump forward to the next actual workday.
 
Upvote 0
...like this:
MrExcel_20240224.xlsx
ACDEFGHIJKL
452/26/2024#days to MS
46Ref Dates"Data generated" DateStart DateDue DateClassHolidaysClassWhenDue3
47Mon, 2/26/24Mon, 2/26/24Mon, 2/26/24Fri, 3/1/24CTue, 2/27/24AABC
48Tue, 2/27/24Tue, 2/27/24Wed, 2/28/24Mon, 3/4/24CB123
49Wed, 2/28/24Wed, 2/28/24Wed, 2/28/24Mon, 3/4/24CC
50Thu, 2/29/24Thu, 2/29/24Thu, 2/29/24Tue, 3/5/24C
51Fri, 3/1/24Fri, 3/1/24Fri, 3/1/24Wed, 3/6/24C
52Sat, 3/2/24Sat, 3/2/24Mon, 3/4/24Thu, 3/7/24C
53Sun, 3/3/24Sun, 3/3/24Mon, 3/4/24Thu, 3/7/24C
54Mon, 3/4/24Mon, 3/4/24Mon, 3/4/24Thu, 3/7/24C
55Tue, 3/5/24Tue, 3/5/24Tue, 3/5/24Fri, 3/8/24C
56Wed, 3/6/24
57Thu, 3/7/24
58Fri, 3/8/24
59Sat, 3/9/24
60Sun, 3/10/24
Sheet6
Cell Formulas
RangeFormula
K46K46=HLOOKUP($F47,WhenDue,2,FALSE)
A47:A60A47=$A$45+SEQUENCE(14,,0)
D47:D55D47=WORKDAY(C47-1,1,Holidays)
E47:E55E47=IF(ISERR(MATCH($F47,Class,0)),0,IF($D47>0,WORKDAY($D47,HLOOKUP($F47,WhenDue,2,FALSE),Holidays),""))
Dynamic array formulas.
Named Ranges
NameRefers ToCells
Class=Sheet6!$I$47:$I$49E47:E55
Holidays=Sheet6!$H$47:$H$53D47:E55
WhenDue=Sheet6!$J$47:$L$48K46, E47:E55

You can incorporate the formula for "jumping" to the first available workday directly into your original formula if desired, rather than breaking it out as a separate formula like my example.
 
Upvote 0
Incorporated into your formula and a slight revision to trap errors differently, see the purple cells:
MrExcel_20240224.xlsx
ACDEFGHIJKL
452/26/2024#days to MS
46Ref Dates"Data generated" DateStart DateDue DateClassHolidaysClassWhenDue3
47Mon, 2/26/24Mon, 2/26/24Mon, 2/26/24Fri, 3/1/24CTue, 2/27/24AABC
48Tue, 2/27/24Tue, 2/27/24Wed, 2/28/24Mon, 3/4/24CB123
49Wed, 2/28/24Wed, 2/28/24Wed, 2/28/24Mon, 3/4/24CC
50Thu, 2/29/24Thu, 2/29/24Thu, 2/29/24Tue, 3/5/24C
51Fri, 3/1/24Fri, 3/1/24Fri, 3/1/24Wed, 3/6/24C
52Sat, 3/2/24Sat, 3/2/24Mon, 3/4/24Thu, 3/7/24C
53Sun, 3/3/24Sun, 3/3/24Mon, 3/4/24Thu, 3/7/24C
54Mon, 3/4/24Mon, 3/4/24Mon, 3/4/24Thu, 3/7/24C
55Tue, 3/5/24Tue, 3/5/24Tue, 3/5/24Fri, 3/8/24C
56Wed, 3/6/24
57Thu, 3/7/24Mon, 2/26/24Fri, 3/1/24C
58Fri, 3/8/24Tue, 2/27/24Mon, 3/4/24C
59Sat, 3/9/24Wed, 2/28/24Mon, 3/4/24C
60Sun, 3/10/24Thu, 2/29/24Tue, 3/5/24C
Sheet6
Cell Formulas
RangeFormula
K46K46=HLOOKUP($F47,WhenDue,2,FALSE)
A47:A60A47=$A$45+SEQUENCE(14,,0)
D47:D55D47=WORKDAY(C47-1,1,Holidays)
E47:E55E47=IF(ISERR(MATCH($F47,Class,0)),0,IF($D47>0,WORKDAY($D47,HLOOKUP($F47,WhenDue,2,FALSE),Holidays),""))
E57:E60E57=IF($D57>0,IFERROR(WORKDAY(WORKDAY($D57-1,1,Holidays),HLOOKUP($F57,WhenDue,2,FALSE),Holidays),""),"")
Dynamic array formulas.
Named Ranges
NameRefers ToCells
Class=Sheet6!$I$47:$I$49E47:E55
Holidays=Sheet6!$H$47:$H$53D47:E55, E57:E60
WhenDue=Sheet6!$J$47:$L$48K46, E47:E55, E57:E60
 
Upvote 0
Solution
Sorry for the delay in response. Your answer worked perfect!! Thank you so much for all your help!
 
Upvote 0
Thanks for the update...that is good news. I'm happy to help.
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,954
Members
449,095
Latest member
nmaske

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