I have this formula that calculates days off for employees, ommitting weekends.…
- User
I have this formula that calculates days off for employees, ommitting weekends. =IF(B4="h", NETWORKDAYS(A4, F4)-1, "") The formula works accurately. However, it does not take into account Public Holidays
I have dates of Public holidays listed in the range AL3:AL26 Is there a way to write a formula that can check if any of the dates in AL3:AL46 fall within the Leave start date in Column A and the end leave date in column F and deduct the number of days found from the final result.
I could add a helper column in AM if you can give me a formula that will check if any date in AL3:AL26 falls within dates enetered in column A and F and output the number of dates found.
- Assistant
To achieve your goal, you can use a helper column to count the number of public holidays that fall within the leave period specified in columns A and F. Here’s a step-by-step approach:
-
Helper Column in AM: Use the following formula in cell AM4 (and drag down for other rows) to count the public holidays between the start date in A4 and end date in F4:
=SUMPRODUCT(--(AL$3:AL$26 >= A4), --(AL$3:AL$26 <= F4))This formula checks each public holiday in the range AL3:AL26 to see if it falls between the dates in A4 and F4, and it counts how many do.
-
Revised Main Formula: Now, you’ll need to adjust your original formula to subtract the count of public holidays from the calculated working days. Your updated formula in Column B should look like this:
=IF(B4="h", NETWORKDAYS(A4, F4) - AM4, "")This formula calculates the number of working days between A4 and F4 and then subtracts the number of holidays counted in AM4.
-
- User
I am getting a #NAME? error with this formula: =SUMPRODUCT(–(AL26 >= A4), --(AL26 <= F4))
- Assistant
The
#NAME?error typically indicates that there's an issue with the syntax in the formula. In the case of yourSUMPRODUCTformula, the problem arises from the use of the long dash (–) instead of the double negative operator (--) to convert the boolean values into numbers.Here's the corrected formula:
=SUMPRODUCT(--(AL$3:AL$26 >= A4), --(AL$3:AL$26 <= F4))Make sure you are using a double dash
--(two hyphens).If you copied and pasted the formula and it still produces an error, you might want to type it out manually to ensure that the characters are recognized correctly.
Explanation of the Formula
AL$3:AL$26 >= A4creates an array of TRUE/FALSE values, where TRUE indicates that the public holiday is on or after the leave start date.- creates another array of TRUE/FALSE values for public holidays that are on or before the leave end date.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.