Calculate No. of Working Days based on Shift Pattern

Sandeep Warrier

Well-known Member
Joined
Oct 31, 2008
Messages
2,680
Hey everyone!

I've been asked to come up with a method to calculate number of working days between 2 dates for people who apply for sick leaves in order to calculate sick pay. The catch is, this needs to be done according to a shift pattern.

A person may work 3 on 4 off shift, or they may work 7 on 4 off shift, or 5 on 3 off shift, and so on. There are about 8-10 different patterns. In addition to the shift pattern, if the total pattern is 7 days (on + off), a person may also work on specific days. For example, if a person works 3 on 4 off shift, those three working days may be a Mon, Tue, Wed or a Tue, Thu, Fri, or any other 3 day combination.

In the first example below, the person works a 4 on 3 off shift, and works on Monday, Wednesday, Friday and Saturday. If the person applies for leave between 21st November and 11th December, they will get a total of 12 working days worth of sick days and pay. In the second example, the person works on a 5 on 4 off shift. For this they get 13 working days worth of sick days and pay.

Here, for the 2nd example, I have assumed that the start date is the start of the shift pattern day, but this may not always be the case. To handle this, if any other info is needed, I can add that as a requirement.

I know I can get the full cycles by dividing the cycle length with the number of days, but calculating the remaining seems to be very tricky, and I'm not able to come up with a logic for this. Any help will be appreciated.

Book1
ABCDEFG
1Start DateEnd DateShiftDays WorkedTotal Working Days
221-11-202411-12-20244 on 3 offMon,Wed,Fri,Sat12
321-11-202411-12-20245 on 4 off13
4
5
6SunMonTueWedThuFriSat
717-Nov18-Nov19-Nov20-Nov21-Nov22-Nov23-Nov
824-Nov25-Nov26-Nov27-Nov28-Nov29-Nov30-Nov
901-Dec02-Dec03-Dec04-Dec05-Dec06-Dec07-Dec
1008-Dec09-Dec10-Dec11-Dec12-Dec13-Dec14-Dec
11
12
13SunMonTueWedThuFriSat
1417-Nov18-Nov19-Nov20-Nov21-Nov22-Nov23-Nov
1524-Nov25-Nov26-Nov27-Nov28-Nov29-Nov30-Nov
1601-Dec02-Dec03-Dec04-Dec05-Dec06-Dec07-Dec
1708-Dec09-Dec10-Dec11-Dec12-Dec13-Dec14-Dec
Sheet1
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Works for 365:

MrExcelPlayground23.xlsx
ABCDEFGHI
1Start DateEnd DateShift OnShift OffDays Worked (Sunday = 1)Sick StartSick FinishTotal Working DaysSickdays needed
211/21/202412/11/2024432,4,6,711/28/202412/4/2024124
311/21/202412/11/20245411/28/202412/4/2024135
Sheet24
Cell Formulas
RangeFormula
H2:I3H2=IF(E2<>"",LET(shift,VALUE(TEXTSPLIT(E2,,",")),start,A2,finish,B2,shifton,C2,shiftoff,D2,sickstart,F2,sickfinish,G2,a,SEQUENCE(finish-start+1,1,start,1),b,WEEKDAY(a,1),c,ISNUMBER(XMATCH(b,shift)),wd,SUM(--c),sd,FILTER(c,(a>=sickstart)*(a<=sickfinish)),sickdays,SUM(--sd),HSTACK(wd,sickdays)),LET(start,A2,finish,B2,shifton,C2,shiftoff,D2,sickstart,F2,sickfinish,G2,a,SEQUENCE(finish-start+1,1,start,1),b,MOD(a-start,shifton+shiftoff)+1,c,b<=shifton,wd,SUM(--c),sd,FILTER(c,(a>=sickstart)*(a<=sickfinish)),sickdays,SUM(--sd),HSTACK(wd,sickdays)))
Dynamic array formulas.
 
Upvote 0
The solution for 7-day patterns (OP Example 1 and similar) seems to be trivial -- NETWORKDAYS.INTL

Here is my take on a solution for x-on/y-off patterns (OP Example 2 and similar). Data layout is as follows:
A3: Start Date, B3: End Date, C3: Number of Days On, D3: Number of Days Off, E3: Pattern Start Date (i.e., first workday of the pattern that falls between the Start Date and End Date).
Excel Formula:
=SUMPRODUCT(--(MOD(ROW(INDEX(A:A,A3):INDEX(A:A,B3))-(MOD(E3-1,C3+D3)+1),C3+D3)<C3))
 
Upvote 0

Forum statistics

Threads
1,224,803
Messages
6,181,055
Members
453,014
Latest member
Chris258

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