Looking for an sequence of consecutive days within an array of dates while ignoring weekends

Lekazard

New Member
Joined
May 25, 2023
Messages
11
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
For a while I have been trying to create a excel sheet, in which a user can input different personnel vacation data and from that data Excel is supposed to form an array of dates and based on some specific conditions it should return in the last column whether the person is granted an extra vacation day.


ArkipyhanTarkastus1-42.xlsm
ABCEFGHIJKLMNO
1UserIDStart_dateEnd_dateHolidayColumn1Column2Column3Column4Column5Column6Column7Column8Column9Column10
2A119.6.202322.6.20231.1.202323.6.202323.6.202323.6.202345096; 45097; 45098; 45099; 4510045096; 45097; 45098; 45099; 45100TRUETRUETRUETRUETRUE
3A220.6.202322.6.20236.1.202323.6.202325.6.202325.6.202345097; 45098; 45099; 45100; 45101; 4510245097; 45098; 45099; 45100; 45101; 45102; 45103FALSEFALSEFALSETRUETRUE
4A226.6.202326.6.20237.4.202326.6.202326.6.202326.6.20234510345097; 45098; 45099; 45100; 45101; 45102; 45103FALSEFALSEFALSETRUETRUE
5A322.6.202322.6.202310.4.202323.6.202325.6.202325.6.202345099; 45100; 45101; 4510245099; 45100; 45101; 45102; 45103; 45104FALSEFALSEFALSETRUETRUE
6A326.6.202327.6.20231.5.202327.6.202327.6.202327.6.202345103; 4510445099; 45100; 45101; 45102; 45103; 45104FALSEFALSEFALSETRUETRUE
7A421.6.202322.6.202318.5.202323.6.202325.6.202325.6.202345098; 45099; 45100; 45101; 4510245098; 45099; 45100; 45101; 45102; 45103FALSEFALSEFALSETRUETRUE
8A426.6.202326.6.202323.6.202326.6.202326.6.202326.6.20234510345098; 45099; 45100; 45101; 45102; 45103FALSEFALSEFALSETRUETRUE
9A520.6.202322.6.20236.12.202323.6.202323.6.202323.6.202345097; 45098; 45099; 4510045097; 45098; 45099; 45100FALSEFALSEFALSETRUETRUE
10A622.6.202322.6.202325.12.202323.6.202325.6.202325.6.202345099; 45100; 45101; 4510245099; 45100; 45101; 45102; 45103; 45104FALSEFALSEFALSETRUETRUE
11A626.6.202326.6.202326.12.202326.6.202326.6.202326.6.20234510345099; 45100; 45101; 45102; 45103; 45104FALSEFALSEFALSETRUETRUE
12A627.6.202327.6.20231.1.202427.6.202327.6.202327.6.20234510445099; 45100; 45101; 45102; 45103; 45104FALSEFALSEFALSETRUETRUE
13A722.6.202322.6.202329.3.202423.6.202325.6.202325.6.202345099; 45100; 45101; 4510245099; 45100; 45101; 45102; 45103; 45104FALSEFALSEFALSETRUETRUE
14A726.6.202326.6.20231.4.202426.6.202326.6.202326.6.20234510345099; 45100; 45101; 45102; 45103; 45104FALSEFALSEFALSETRUETRUE
15A727.6.202327.6.20231.5.202427.6.202327.6.202327.6.20234510445099; 45100; 45101; 45102; 45103; 45104FALSEFALSEFALSETRUETRUE
16A821.6.202322.6.20239.5.202423.6.202325.6.202325.6.202345098; 45099; 45100; 45101; 4510245098; 45099; 45100; 45101; 45102; 45103; 45104; 45105FALSEFALSEFALSETRUETRUE
17A826.6.202327.6.202321.6.202327.6.202327.6.202327.6.202345103; 4510445098; 45099; 45100; 45101; 45102; 45103; 45104; 45105FALSEFALSEFALSETRUETRUE
18A828.6.202328.6.20236.12.202428.6.202328.6.202328.6.20234510545098; 45099; 45100; 45101; 45102; 45103; 45104; 45105FALSEFALSEFALSETRUETRUE
19B122.6.202322.6.202324.12.202423.6.202323.6.202323.6.202345099; 4510045099; 45100FALSEFALSEFALSEFALSE 
20B226.6.202326.6.202325.12.202426.6.202326.6.202326.6.20234510345103FALSEFALSEFALSEFALSE 
21B321.6.202322.6.202326.12.202423.6.202323.6.202323.6.202345098; 45099; 4510045098; 45099; 45100FALSEFALSEFALSEFALSE 
22B422.6.202322.6.20231.1.202523.6.202323.6.202323.6.202345099; 4510045099; 45100; 45104; 45105; 45106FALSEFALSEFALSEFALSE 
23B427.6.202329.6.20236.1.202529.6.202329.6.202329.6.202345104; 45105; 4510645099; 45100; 45104; 45105; 45106FALSEFALSEFALSEFALSE 
24B521.6.202322.6.202318.4.202523.6.202323.6.202323.6.202345098; 45099; 4510045098; 45099; 45100FALSEFALSEFALSEFALSE 
25B621.6.202322.6.202321.4.202523.6.202323.6.202323.6.202345098; 45099; 4510045098; 45099; 45100; 45110; 45111FALSEFALSEFALSEFALSE 
26B63.7.20234.7.20231.5.20254.7.20234.7.20234.7.202345110; 4511145098; 45099; 45100; 45110; 45111FALSEFALSEFALSEFALSE 
27B722.6.202322.6.202329.5.202523.6.202323.6.202323.6.202345099; 4510045099; 45100; 45103FALSEFALSEFALSEFALSE 
28B726.6.202326.6.202320.6.202526.6.202326.6.202326.6.20234510345099; 45100; 45103FALSEFALSEFALSEFALSE 
29B821.6.202322.6.202324.12.202523.6.202323.6.202323.6.202345098; 45099; 4510045098; 45099; 45100FALSEFALSEFALSEFALSE 
30B926.6.202326.6.202325.12.202526.6.202326.6.202326.6.20234510345103; 45104; 45105FALSEFALSEFALSEFALSE 
31B927.6.202327.6.202326.12.202527.6.202327.6.202327.6.20234510445103; 45104; 45105FALSEFALSEFALSEFALSE 
32B928.6.202328.6.202328.6.202328.6.202328.6.20234510545103; 45104; 45105FALSEFALSEFALSEFALSE 
Sheet1
Cell Formulas
RangeFormula
F2:F32F2=IF(COUNTIFS($E$2:$E$101, C2+1) > 0, C2+1, C2)
G2:G32G2=IF(AND(B2=C2, B3=C3, A1<>A2, A3<>A4), F2, IF(AND(A2=A3, WEEKDAY(F2, 2)=5, WEEKDAY(B3, 2)=1, B3-F2<=3, IF(B2<>OFFSET(B2, -1, 0), B3<>OFFSET(C3, -1, 0), TRUE), OR(A1<>A2, A4<>A2)), F2+2, F2))
H2:H32H2=IF(AND(WEEKDAY(G2, 3) = 5, A2 = A3, F3 = WORKDAY(G2, 3), F3 - G2 <= 3, OR(B2 <> C2, B3 <> C3)), G2 + 2, G2)
I2:I32I2=TEXTJOIN("; ", TRUE, SEQUENCE(G2-B2+1, 1, B2))
J2:J32J2=TEXTJOIN("; ",TRUE,IF($A$2:$A$5203=A2,I$2:I$5001,""))
K2:K32K2=IF(C2-B2>2,OR(BYROW(E$2:E$100,LAMBDA(rw,ISNUMBER(FIND(TEXTJOIN("; ",,SEQUENCE(4,,rw-1)),J2)))),FALSE))
L2:L32L2=IF(C2-B2>2,OR(BYROW(E$2:E$100,LAMBDA(rw,ISNUMBER(FIND(TEXTJOIN("; ",,SEQUENCE(4,,rw-2)),J2)))),FALSE))
M2:M32M2=IF(C2-B2>2,OR(BYROW(E$2:E$100,LAMBDA(rw,ISNUMBER(FIND(TEXTJOIN("; ",,SEQUENCE(4,,rw-3)),J2)))),FALSE))
N2:N32N2=OR(OR(BYROW(E$2:E$100,LAMBDA(rw,ISNUMBER(FIND(TEXTJOIN("; ",,SEQUENCE(4,,rw-1)),J2))))), OR(BYROW(E$2:E$100,LAMBDA(rw,ISNUMBER(FIND(TEXTJOIN("; ",,SEQUENCE(4,,rw-2)),J2))))), OR(BYROW(E$2:E$100,LAMBDA(rw,ISNUMBER(FIND(TEXTJOIN("; ",,SEQUENCE(4,,rw-3)),J2))))))
O2:O32O2=IF(N2=TRUE, TRUE, "")
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A2:C5000Expression=$O2=TRUEtextNO
O2:O4799Expression=$O2=TRUEtextNO


The sheet is supposed to work in an a way that the user inserts the personnel data into columns A-C and then column O gives a boolean output depending on whether the specific conditions are met for the extra vacation day or not. As a result column O should be TRUE if one of these conditions are met:

- The person has 3 consecutive vacation days right before any of the days listed in column E
- The person has 2 consecutive vacation days right before any of the days listed in column E and 1 right after it
- The person has a vacation day right before any of the days listed in column E and 2 consecutive days right after it

So originally with the help of people over here I decided to solve this by forming an array of dates for each user. For each row a date range is formed based on the values in columns B and C and if the UserID is the same as in the previous row then those date ranges are added up creating an array, in which all the days when the person is on vacation are listed. This array is in column J. Then the functions in rows K-M check whether the array has 4 consecutive days and checking for conditions listed above and if any one of the conditions are met, then it returns TRUE and highlights the row for convenience (for some reason besides the 2nd row they all seem to display FALSE even though they seem to function as intended).

There's just one problem which I didn't take under consideration beforehand: weekends. When counting consecutive days I should've been only counting workdays. I've been trying to solve this issue in columns F-H by using WEEKDAY-function and various conditions to check if the end date is Friday and then expanding the original end date into Sunday to have those days also included into the array, but I've realized that this approach is way too complex and prone to bugs. The WORKDAY-function could be the solution to begin with, but since the dates in the array are converted into text format, the use of WORKDAY-function is problematic also.

I've been trying to solve this issue the whole week, but I feel like I'm way beyond my league here. Any help from people smarter than me is again highly appreciated.
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Give this a go? Pretty sure variable _c can be simplified further though.
Book64
ABCDEFG
1UserIDStart_dateEnd_dateHoliday
2A119-Jun-2322-Jun-2301-Jan-23TRUE
3A220-Jun-2322-Jun-2306-Jan-23FALSE
4A226-Jun-2326-Jun-2307-Apr-23FALSE
5A322-Jun-2322-Jun-2310-Apr-23FALSE
6A326-Jun-2327-Jun-2301-May-23FALSE
7A421-Jun-2322-Jun-2318-May-23FALSE
8A426-Jun-2326-Jun-2323-Jun-23FALSE
9A520-Jun-2322-Jun-2306-Dec-23FALSE
10A622-Jun-2322-Jun-2325-Dec-23FALSE
11A626-Jun-2326-Jun-2326-Dec-23FALSE
12A627-Jun-2327-Jun-2301-Jan-24FALSE
13A722-Jun-2322-Jun-2329-Mar-24FALSE
14A726-Jun-2326-Jun-2301-Apr-24FALSE
15A727-Jun-2327-Jun-2301-May-24FALSE
16A821-Jun-2322-Jun-2309-May-24FALSE
17A826-Jun-2327-Jun-2321-Jun-23FALSE
18A828-Jun-2328-Jun-2306-Dec-24FALSE
19B122-Jun-2322-Jun-2324-Dec-24FALSE
20B226-Jun-2326-Jun-2325-Dec-24FALSE
21B321-Jun-2322-Jun-2326-Dec-24FALSE
22B422-Jun-2322-Jun-2301-Jan-25FALSE
23B427-Jun-2329-Jun-2306-Jan-25FALSE
24B521-Jun-2322-Jun-2318-Apr-25FALSE
25B621-Jun-2322-Jun-2321-Apr-25FALSE
26B603-Jul-2304-Jul-2301-May-25FALSE
27B722-Jun-2322-Jun-2329-May-25FALSE
28B726-Jun-2326-Jun-2320-Jun-25FALSE
29B821-Jun-2322-Jun-2324-Dec-25FALSE
30B926-Jun-2326-Jun-2325-Dec-25FALSE
31B927-Jun-2327-Jun-2326-Dec-25FALSE
32B928-Jun-2328-Jun-23FALSE
Sheet3
Cell Formulas
RangeFormula
G2:G32G2=LET( _a,WORKDAY(B2-1,SEQUENCE(NETWORKDAYS(B2,C2))), _b,IFNA(XMATCH($E$2:$E$31,_a),0), _c,((_b>3)+(_b>2)*(_b<ROWS(_a))+(_b>1)*(_b<ROWS(_a)-1))*(ROWS(_a)-SUM(SIGN(_b))>=3), SIGN(SUM(_c))=1)
 
Last edited:
Upvote 0
Give this a go? Pretty sure variable _c can be simplified further though.
Book64
ABCDEFG
1UserIDStart_dateEnd_dateHoliday
2A119-Jun-2322-Jun-2301-Jan-23TRUE
3A220-Jun-2322-Jun-2306-Jan-23FALSE
4A226-Jun-2326-Jun-2307-Apr-23FALSE
5A322-Jun-2322-Jun-2310-Apr-23FALSE
6A326-Jun-2327-Jun-2301-May-23FALSE
7A421-Jun-2322-Jun-2318-May-23FALSE
8A426-Jun-2326-Jun-2323-Jun-23FALSE
9A520-Jun-2322-Jun-2306-Dec-23FALSE
10A622-Jun-2322-Jun-2325-Dec-23FALSE
11A626-Jun-2326-Jun-2326-Dec-23FALSE
12A627-Jun-2327-Jun-2301-Jan-24FALSE
13A722-Jun-2322-Jun-2329-Mar-24FALSE
14A726-Jun-2326-Jun-2301-Apr-24FALSE
15A727-Jun-2327-Jun-2301-May-24FALSE
16A821-Jun-2322-Jun-2309-May-24FALSE
17A826-Jun-2327-Jun-2321-Jun-23FALSE
18A828-Jun-2328-Jun-2306-Dec-24FALSE
19B122-Jun-2322-Jun-2324-Dec-24FALSE
20B226-Jun-2326-Jun-2325-Dec-24FALSE
21B321-Jun-2322-Jun-2326-Dec-24FALSE
22B422-Jun-2322-Jun-2301-Jan-25FALSE
23B427-Jun-2329-Jun-2306-Jan-25FALSE
24B521-Jun-2322-Jun-2318-Apr-25FALSE
25B621-Jun-2322-Jun-2321-Apr-25FALSE
26B603-Jul-2304-Jul-2301-May-25FALSE
27B722-Jun-2322-Jun-2329-May-25FALSE
28B726-Jun-2326-Jun-2320-Jun-25FALSE
29B821-Jun-2322-Jun-2324-Dec-25FALSE
30B926-Jun-2326-Jun-2325-Dec-25FALSE
31B927-Jun-2327-Jun-2326-Dec-25FALSE
32B928-Jun-2328-Jun-23FALSE
Sheet3
Cell Formulas
RangeFormula
G2:G32G2=LET( _a,WORKDAY(B2-1,SEQUENCE(NETWORKDAYS(B2,C2))), _b,IFNA(XMATCH($E$2:$E$31,_a),0), _c,((_b>3)+(_b>2)*(_b<ROWS(_a))+(_b>1)*(_b<ROWS(_a)-1))*(ROWS(_a)-SUM(SIGN(_b))>=3), SIGN(SUM(_c))=1)
Thanks for the suggestion. What I can tell from the formula you suggested, the formula checks if certain conditions are met for a specified vacation period. It creates a series of workdays between the start and end dates of the vacation, excluding weekends and holidays. Then, it compares these days to a list of specific dates and checks if there are 3 consecutive days or 2 consecutive days with a day before or after those specific dates, and if the vacation period is at least 3 days long. If all conditions are met, the formula returns TRUE; otherwise, it returns FALSE.

Unfortunately the issue is a bit more complex. With this formula there's the assumption, that there's only a single date range starting from the date in column B and ending in column C (if I understood it correctly, I might be wrong here). But what makes issue more complicated is that I first need to take under consideration the fact that the actual range of dates is divided into multiple rows and before doing the condition checking all those rows need to be merged together to get the valid date range which has vacation days for a single UserID.

In this example data I provided I've constructed it in a way, that the users starting with the letter A (rows 2-18) should fulfill the conditions and get the output TRUE and users starting with the letter B (rows 19-32) should get FALSE.
 
Upvote 0
In that case, how would you count the total extra vacation days? Do some date ranges comprise holidays while others do not? Do they get one extra vacation day for every instance of 3 consecutive weekdays around a vacation? (i.e. is A6 entitled to 3 extra days since all 3 rows say TRUE?)
 
Upvote 0
In that case, how would you count the total extra vacation days? Do some date ranges comprise holidays while others do not? Do they get one extra vacation day for every instance of 3 consecutive weekdays around a vacation? (i.e. is A6 entitled to 3 extra days since all 3 rows say TRUE?)
The extra vacations are granted just once for a single user, in the case of A6 his vacation should be considered ranging from 22-Jun to 27-Jun. Since we are only counting workdays, it fulfills the condition of 1 day before E8 and 2 days after. That's the reason why I initially merged the dates into one array in column J so I could treat the multiple date ranges as a whole.
The problems with this approach are visible if you look at December 2024, where Christmas eve is Tuesday, Christmas Day is Wednesday, and Boxing day is Thursday. This is the biggest reason why I need to only workdays under consideration because manually creating conditions for each case gets way too complex. And in the case of that Christmas, the following vacatation day combinations should give the output of TRUE:

- 19-Dec, 20-Dec, 23-Dec (Thu, Fri, Mon)
- 20-Dec, 23-Dec, 27-Dec (Fri, Mon, Fri)
- 23-Dec, 27-Dec, 30-Dec (Mon, Fri, Mon)

In these cases the 3 Christmas holidays are considered just as one and if any of these conditions are met, the person is granted 1 extra day, not 3. But with the combination of 23-Dec, 27-Dec, 30-Dec and 31-Dec the user should be granted a 2nd extra vacation day from New Years Day.
I hope I managed to clarify the issue enough to make it understandable.
 
Upvote 0
A4 and A5 don't qualify as 21 Jun 2023 is a holiday. A1 and A2 appear to qualify for 2 holidays since 21 Jun 2023 and 23 Jun 2023 are not consecutive. Column J onwards is just the formula broken into parts. I'm not trying beyond this:

Book73
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAMANAOAPAQARASAT
1UserIDStart_dateEnd_dateHoliday
2A119-Jun-2322-Jun-2301-Jan-23A12.00
3A220-Jun-2322-Jun-2306-Jan-23A22.00
4A226-Jun-2326-Jun-2307-Apr-23A31.00
5A322-Jun-2322-Jun-2310-Apr-23A40.00
6A326-Jun-2327-Jun-2301-May-23A50.00
7A421-Jun-2322-Jun-2318-May-23A61.00
8A426-Jun-2326-Jun-2323-Jun-23A71.00
9A520-Jun-2322-Jun-2306-Dec-23A81.00
10A622-Jun-2322-Jun-2325-Dec-23B10.00
11A626-Jun-2326-Jun-2326-Dec-23B20.00
12A627-Jun-2327-Jun-2301-Jan-24B30.00
13A722-Jun-2322-Jun-2329-Mar-24B40.00
14A726-Jun-2326-Jun-2301-Apr-24B50.00
15A727-Jun-2327-Jun-2301-May-24B60.00
16A821-Jun-2322-Jun-2309-May-24B70.00abcdeconres
17A826-Jun-2327-Jun-2321-Jun-23B80.0021-Jun-2328-Jun-2322-Jun-2321-Jun-2322-Jun-23TRUEFALSEFALSETRUETRUETRUE100122-Jun-2328-Dec-2229-Dec-2230-Dec-2229-Dec-2230-Dec-2202-Jan-2330-Dec-2202-Jan-2303-Jan-23000000000000
18A828-Jun-2328-Jun-2306-Dec-24B90.0026-Jun-2326-Jun-2327-Jun-23TRUETRUEFALSEFALSETRUETRUE010126-Jun-2303-Jan-2304-Jan-2305-Jan-2304-Jan-2305-Jan-2309-Jan-2305-Jan-2309-Jan-2310-Jan-23000000000000
19B122-Jun-2322-Jun-2324-Dec-2427-Jun-2328-Jun-2328-Jun-23TRUETRUEFALSEFALSETRUETRUE010127-Jun-2304-Apr-2305-Apr-2306-Apr-2305-Apr-2306-Apr-2311-Apr-2306-Apr-2311-Apr-2312-Apr-23000000000000
20B226-Jun-2326-Jun-2325-Dec-2428-Jun-23TRUETRUETRUEFALSEFALSETRUE001128-Jun-2326-Apr-2327-Apr-2328-Apr-2327-Apr-2328-Apr-2302-May-2328-Apr-2302-May-2303-May-23000000000000
21B321-Jun-2322-Jun-2326-Dec-2415-May-2316-May-2317-May-2316-May-2317-May-2319-May-2317-May-2319-May-2322-May-23000000000000
22B422-Jun-2322-Jun-2301-Jan-2519-Jun-2320-Jun-2322-Jun-2320-Jun-2322-Jun-2326-Jun-2322-Jun-2326-Jun-2327-Jun-23001012123001
23B427-Jun-2329-Jun-2306-Jan-2501-Dec-2304-Dec-2305-Dec-2304-Dec-2305-Dec-2307-Dec-2305-Dec-2307-Dec-2308-Dec-23000000000000
24B521-Jun-2322-Jun-2318-Apr-2520-Dec-2321-Dec-2322-Dec-2321-Dec-2322-Dec-2327-Dec-2322-Dec-2327-Dec-2328-Dec-23000000000000
25B621-Jun-2322-Jun-2321-Apr-2527-Dec-2328-Dec-2329-Dec-2328-Dec-2329-Dec-2302-Jan-2429-Dec-2302-Jan-2403-Jan-24000000000000
26B603-Jul-2304-Jul-2301-May-2526-Mar-2427-Mar-2428-Mar-2427-Mar-2428-Mar-2402-Apr-2428-Mar-2402-Apr-2403-Apr-24000000000000
27B722-Jun-2322-Jun-2329-May-2526-Apr-2429-Apr-2430-Apr-2429-Apr-2430-Apr-2402-May-2430-Apr-2402-May-2403-May-24000000000000
28B726-Jun-2326-Jun-2320-Jun-2506-May-2407-May-2408-May-2407-May-2408-May-2410-May-2408-May-2410-May-2413-May-24000000000000
29B821-Jun-2322-Jun-2324-Dec-2516-Jun-2319-Jun-2320-Jun-2319-Jun-2320-Jun-2322-Jun-2320-Jun-2322-Jun-2326-Jun-23000001012000
30B926-Jun-2326-Jun-2325-Dec-2503-Dec-2404-Dec-2405-Dec-2404-Dec-2405-Dec-2409-Dec-2405-Dec-2409-Dec-2410-Dec-24000000000000
31B927-Jun-2327-Jun-2326-Dec-2519-Dec-2420-Dec-2423-Dec-2420-Dec-2423-Dec-2427-Dec-2423-Dec-2427-Dec-2430-Dec-24000000000000
32B928-Jun-2328-Jun-2327-Dec-2430-Dec-2431-Dec-2430-Dec-2431-Dec-2402-Jan-2531-Dec-2402-Jan-2503-Jan-25000000000000
3331-Dec-2402-Jan-2503-Jan-2502-Jan-2503-Jan-2507-Jan-2503-Jan-2507-Jan-2508-Jan-25000000000000
3415-Apr-2516-Apr-2517-Apr-2516-Apr-2517-Apr-2522-Apr-2517-Apr-2522-Apr-2523-Apr-25000000000000
3528-Apr-2529-Apr-2530-Apr-2529-Apr-2530-Apr-2502-May-2530-Apr-2502-May-2505-May-25000000000000
3626-May-2527-May-2528-May-2527-May-2528-May-2530-May-2528-May-2530-May-2502-Jun-25000000000000
3717-Jun-2518-Jun-2519-Jun-2518-Jun-2519-Jun-2523-Jun-2519-Jun-2523-Jun-2524-Jun-25000000000000
3819-Dec-2522-Dec-2523-Dec-2522-Dec-2523-Dec-2529-Dec-2523-Dec-2529-Dec-2530-Dec-25000000000000
Sheet5
Cell Formulas
RangeFormula
G2:G18G2=UNIQUE(A2:A32)
J17J17=MINIFS($B$2:$B$32,$A$2:$A$32,A17)
K17K17=MAXIFS($C$2:$C$32,$A$2:$A$32,A17)
L17:L20L17=WORKDAY(WORKDAY(J17,-1,E3:E32),SEQUENCE(NETWORKDAYS(J17,K17,$E$3:$E$32)),$E$3:$E$32)
M17:M19M17=FILTER(B2:B32,A2:A32=A17)
N17:N19N17=FILTER(C2:C32,A2:A32=A17)
O17:Q20O17=L17#>=TRANSPOSE(M17#)
R17:T20R17=L17#<=TRANSPOSE(N17#)
U17:W20U17=O17#*R17#
X17:X20X17=MMULT(U17#,SEQUENCE(3,,,0))
Y17:Y20Y17=FILTER(L17#,X17#)
Z17:AB38Z17=UNIQUE(WORKDAY(WORKDAY(--E2:E31,-4,E2:E31),SEQUENCE(1,3),E2:E31))
AC17:AE38AC17=UNIQUE(WORKDAY(WORKDAY(--E2:E31,-3,E2:E31),SEQUENCE(1,3),E2:E31))
AF17:AH38AF17=UNIQUE(WORKDAY(WORKDAY(--E2:E31,-2,E2:E31),SEQUENCE(1,3),E2:E31))
AI17:AK38AI17=IFNA(XMATCH(Z17#,Y17#),0)
AL17:AN38AL17=IFNA(XMATCH(AC17#,Y17#),0)
AO17:AQ38AO17=IFNA(XMATCH(AF17#,Y17#),0)
AR17:AR38AR17=--(MMULT(SIGN(AI17#),SEQUENCE(3,,,0))=3)
AS17:AS38AS17=--(MMULT(SIGN(AL17#),SEQUENCE(3,,,0))=3)
AT17:AT38AT17=--(MMULT(SIGN(AO17#),SEQUENCE(3,,,0))=3)
H2:H18H2=LET( data,$A$2:$C$32, hol,$E$2:$E$31, user,G2, d_1,INDEX(data,0,1), d_2,INDEX(data,0,2), d_3,INDEX(data,0,3), start,MINIFS(d_2,d_1,user), end,MAXIFS(d_3,d_1,user), _a,WORKDAY(WORKDAY(start,-1,hol),SEQUENCE(NETWORKDAYS(start,end,hol)),hol), _b,FILTER(d_2,d_1=user), _c,FILTER(d_3,d_1=user), _d,(_a>=TRANSPOSE(_b))*(_a<=TRANSPOSE(_c)), _e,FILTER(_a,MMULT(_d,SEQUENCE(COLUMNS(_d),,,0))), con_1,UNIQUE(WORKDAY(WORKDAY(--hol,-4,hol),SEQUENCE(1,3),hol)), con_2,UNIQUE(WORKDAY(WORKDAY(--hol,-3,hol),SEQUENCE(1,3),hol)), con_3,UNIQUE(WORKDAY(WORKDAY(--hol,-2,hol),SEQUENCE(1,3),hol)), res_1,--(MMULT(SIGN(IFNA(XMATCH(con_1,_e),0)),SEQUENCE(3,,,0))=3), res_2,--(MMULT(SIGN(IFNA(XMATCH(con_2,_e),0)),SEQUENCE(3,,,0))=3), res_3,--(MMULT(SIGN(IFNA(XMATCH(con_3,_e),0)),SEQUENCE(3,,,0))=3), IFERROR(SUM(res_1+res_2+res_3),0))
Dynamic array formulas.
 
Upvote 1
Solution
There was a mistake where it would double count extra days if it fulfilled more than one condition, the last line should have an additional SIGN function, as in
Excel Formula:
IFERROR(SUM(SIGN((res_1+res_2+res_3))),0)
 
Upvote 0

Forum statistics

Threads
1,223,950
Messages
6,175,582
Members
452,653
Latest member
craigje92

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