Count all overlapping days from range between another set of dates

Pepperoni

New Member
Joined
Nov 30, 2021
Messages
9
Office Version
  1. 365
Platform
  1. Windows
Hello everyone!

I currently have this spreadsheet in progress that will be used as a template to decipher a repayment period. Users will enter a start date into the 'Payslip Start Date' and 'Repayment Start Date', then enter the hours from a payslip and we have to calculate the total for each week.

I am having a lot of trouble finding the right formula to use that will correctly count the individual days of the 'Payslip Start' and 'Payslip End' dates that fit within the 'Payment Start' and 'Payment End' date period (see B9:B34-C9:C34 and J9:J34-K9:K34).

As you can see from the attached, in column L, I was playing around with a MIN/Max formula, however it will only work correctly if the dates exactly match in both sets of columns (see below). In this case, the '14' in column L is correct as there are the 14 days from the 01/01/2022 - 14/01/2022 (in B and C) that align with the date ranges in J and K.

Book2.xlsx
ABCDEFGHIJKLMN
1Payslip PeriodsFortnightly14
2Payment FrequencyFortnightly
3Payment Start Date1/01/2022
4Payment End Date2/07/2022
5Total Payable
6Payslip Start Date1/01/2022
7
8Payslip StartPayslip EndTotal HoursDaily Rate HRSCumulative HRS in PayslipsCumulative Average Hours per Payment Due WeekPayment Period StartPayment Period End
91/01/202214/01/2022201.4314.0020.0020.001/01/202214/01/20221400
1015/01/202228/01/2022201.430.0020.0020.0015/01/202228/01/20221400
1129/01/202211/02/2022201.430.0020.0020.0029/01/202211/02/20221400
1212/02/202225/02/2022201.430.0020.0020.0012/02/202225/02/20221400
1326/02/202211/03/2022201.430.0020.0020.0026/02/202211/03/20221400
1412/03/202225/03/2022201.430.0020.0020.0012/03/202225/03/20221400
1526/03/20228/04/2022201.430.0020.0020.0026/03/20228/04/20221400
169/04/202222/04/2022201.430.0020.0020.009/04/202222/04/20221400
1723/04/20226/05/2022201.430.0020.0020.0023/04/20226/05/20221400
187/05/202220/05/2022201.430.0020.0020.007/05/202220/05/20221400
1921/05/20223/06/2022201.430.0020.0020.0021/05/20223/06/20221400
204/06/202217/06/2022201.430.0020.0020.004/06/202217/06/2022140 
2118/06/20221/07/2022201.430.0020.0020.0018/06/20221/07/202214  
220.000.000.0018.57
230.000.000.0017.33
240.000.000.0016.25
250.000.000.0015.29
260.000.000.0014.44
270.000.000.0013.68
280.000.000.0013.00
290.000.000.0012.38
300.000.000.0011.82
310.000.000.0011.30
320.000.000.0010.83
330.000.000.0010.40
340.000.000.0010.00
Sheet1
Cell Formulas
RangeFormula
D1D1=IFS(B1="Weekly","7",B1="Fortnightly","14",B1="Monthly","30.31")
B4B4=($B$3+182)
B9:B21B9=LET(p,MATCH(B1,{"Weekly","Fortnightly","Monthly"},0),SEQUENCE(CHOOSE(p,26,13,6),,B6,CHOOSE(p,7,14,30.41)))
C9:C21C9=B9#+IF(B1="Weekly",6,IF(B1="Monthly",29.41,13))
E9:E34E9=D9/$D$1
F9:F34F9=LET(Y,SEQUENCE(K9-J9+1),X,TRANSPOSE(J9+Y-1),MMULT((X>=B9:B34)*(X<=C9:C34),Y^0))
G9:G34G9=SUMPRODUCT(($B$9:$B$34>=J9)*($C$9:$C$34<=K9)*$D$9:$D$34)
H9H9=D9/1
H10H10=SUM(D9:D10)/2
H11H11=SUM(D9:D11)/3
H12H12=SUM(D9:D12)/4
H13H13=SUM(D9:D13)/5
H14H14=SUM(D9:D14)/6
H15H15=SUM(D9:D15)/7
H16H16=SUM(D9:D16)/8
H17H17=SUM(D9:D17)/9
H18H18=SUM(D9:D18)/10
H19H19=SUM(D9:D19)/11
H20H20=SUM(D9:D20)/12
H21H21=SUM(D9:D21)/13
H22H22=SUM(D9:D22)/14
H23H23=SUM(D9:D23)/15
H24H24=SUM(D9:D24)/16
H25H25=SUM(D9:D25)/17
H26H26=SUM(D9:D26)/18
H27H27=SUM(D9:D27)/19
H28H28=SUM(D9:D28)/20
H29H29=SUM(D9:D29)/21
H30H30=SUM(D9:D30)/22
H31H31=SUM(D9:D31)/23
H32H32=SUM(D9:D32)/24
H33H33=SUM(D9:D33)/25
H34H34=SUM(D9:D34)/26
J9:J21J9=LET(p,MATCH(B2,{"Fortnightly","Monthly","Quarterly","Milestone","Lump Sum"},0),SEQUENCE(CHOOSE(p,13,6,2,2,1),,B3,CHOOSE(p,14,30.41,91,91,182)))
K9:K21K9=J9#+IFS(B2="Fortnightly",13,B2="Monthly",29.41,B2="Quarterly",90,B2="Quarterly",90,B2="Milestone",90,B2="Lump Sum",181)
L9:L21L9=IF($B9<>"",TRANSPOSE(MAX(MIN($K9,$C9)-MAX($J9,$B9)+1,0)),"")
M9:M21M9=IF($B10<>"",TRANSPOSE(MAX(MIN($K9,$C10)-MAX($J9,$B10)+1,0)),"")
N9:N21N9=IF($B11<>"",TRANSPOSE(MAX(MIN($K9,$C11)-MAX($J9,$B11)+1,0)),"")
Press CTRL+SHIFT+ENTER to enter array formulas.
Dynamic array formulas.
Cells with Conditional Formatting
CellConditionCell FormatStop If True
H9:H34Cell Value>=20textNO


However, if I was to change the Payslip Start to the 05/01/2022, it will only count '10 days' but continues to repeat that. I understand that it will always read the same as there are only ever 10 numbers in the row that align, however I am hoping that will be able to recognise somehow that the row beneath it contains some of the date range as well. If the formula works, it should hopefully show (or something like it). i.e.
Row 1: 05/01/2022 - 18/01/2022 has 10 days that fit within the 01/01/2022 - 14/01/2022 but the remaining 4 days fit into row 2 (15/01/2022 - 28/01/2022).

Payslip StartPayslip EndPayment Period StartPayment Period End
5/01/2022​
18/01/2022​
01/01/202214/01/202210
19/01/2022​
1/02/2022​
15/01/202228/01/20224 (the remaining 4 days in row 1 fit into this payment period)
2/02/2022​
15/02/2022​
29/01/202211/02/2022
16/02/2022​
1/03/2022​
12/02/202225/02/2022
2/03/2022​
15/03/2022​
26/02/202211/03/2022
16/03/2022​
29/03/2022​
12/03/202225/03/2022
30/03/2022​
12/04/2022​
26/03/202208/04/2022
13/04/2022​
26/04/2022​
09/04/202222/04/2022
27/04/2022​
10/05/2022​
23/04/202206/05/2022
11/05/2022​
24/05/2022​
07/05/202220/05/2022
25/05/2022​
7/06/2022​
21/05/202203/06/2022
8/06/2022​
21/06/2022​
04/06/202217/06/2022
22/06/2022​
5/07/2022​
18/06/202201/07/2022

Counting the individual days will be important as if a payment period end durings the middle of the week (for example), we would then need to work out the daily rate of hours and times that by the number of days actually completed in the payment period. I am thinking that I will need to extend the columns in J and K to include all of the possibles date combinations, but I thought I would ask if it could be done first?

Thank you all so much!
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Hello everyone!

I currently have this spreadsheet in progress that will be used as a template to decipher a repayment period. Users will enter a start date into the 'Payslip Start Date' and 'Repayment Start Date', then enter the hours from a payslip and we have to calculate the total for each week.

I am having a lot of trouble finding the right formula to use that will correctly count the individual days of the 'Payslip Start' and 'Payslip End' dates that fit within the 'Payment Start' and 'Payment End' date period (see B9:B34-C9:C34 and J9:J34-K9:K34).

As you can see from the attached, in column L, I was playing around with a MIN/Max formula, however it will only work correctly if the dates exactly match in both sets of columns (see below). In this case, the '14' in column L is correct as there are the 14 days from the 01/01/2022 - 14/01/2022 (in B and C) that align with the date ranges in J and K.

Book2.xlsx
ABCDEFGHIJKLMN
1Payslip PeriodsFortnightly14
2Payment FrequencyFortnightly
3Payment Start Date1/01/2022
4Payment End Date2/07/2022
5Total Payable
6Payslip Start Date1/01/2022
7
8Payslip StartPayslip EndTotal HoursDaily Rate HRSCumulative HRS in PayslipsCumulative Average Hours per Payment Due WeekPayment Period StartPayment Period End
91/01/202214/01/2022201.4314.0020.0020.001/01/202214/01/20221400
1015/01/202228/01/2022201.430.0020.0020.0015/01/202228/01/20221400
1129/01/202211/02/2022201.430.0020.0020.0029/01/202211/02/20221400
1212/02/202225/02/2022201.430.0020.0020.0012/02/202225/02/20221400
1326/02/202211/03/2022201.430.0020.0020.0026/02/202211/03/20221400
1412/03/202225/03/2022201.430.0020.0020.0012/03/202225/03/20221400
1526/03/20228/04/2022201.430.0020.0020.0026/03/20228/04/20221400
169/04/202222/04/2022201.430.0020.0020.009/04/202222/04/20221400
1723/04/20226/05/2022201.430.0020.0020.0023/04/20226/05/20221400
187/05/202220/05/2022201.430.0020.0020.007/05/202220/05/20221400
1921/05/20223/06/2022201.430.0020.0020.0021/05/20223/06/20221400
204/06/202217/06/2022201.430.0020.0020.004/06/202217/06/2022140 
2118/06/20221/07/2022201.430.0020.0020.0018/06/20221/07/202214  
220.000.000.0018.57
230.000.000.0017.33
240.000.000.0016.25
250.000.000.0015.29
260.000.000.0014.44
270.000.000.0013.68
280.000.000.0013.00
290.000.000.0012.38
300.000.000.0011.82
310.000.000.0011.30
320.000.000.0010.83
330.000.000.0010.40
340.000.000.0010.00
Sheet1
Cell Formulas
RangeFormula
D1D1=IFS(B1="Weekly","7",B1="Fortnightly","14",B1="Monthly","30.31")
B4B4=($B$3+182)
B9:B21B9=LET(p,MATCH(B1,{"Weekly","Fortnightly","Monthly"},0),SEQUENCE(CHOOSE(p,26,13,6),,B6,CHOOSE(p,7,14,30.41)))
C9:C21C9=B9#+IF(B1="Weekly",6,IF(B1="Monthly",29.41,13))
E9:E34E9=D9/$D$1
F9:F34F9=LET(Y,SEQUENCE(K9-J9+1),X,TRANSPOSE(J9+Y-1),MMULT((X>=B9:B34)*(X<=C9:C34),Y^0))
G9:G34G9=SUMPRODUCT(($B$9:$B$34>=J9)*($C$9:$C$34<=K9)*$D$9:$D$34)
H9H9=D9/1
H10H10=SUM(D9:D10)/2
H11H11=SUM(D9:D11)/3
H12H12=SUM(D9:D12)/4
H13H13=SUM(D9:D13)/5
H14H14=SUM(D9:D14)/6
H15H15=SUM(D9:D15)/7
H16H16=SUM(D9:D16)/8
H17H17=SUM(D9:D17)/9
H18H18=SUM(D9:D18)/10
H19H19=SUM(D9:D19)/11
H20H20=SUM(D9:D20)/12
H21H21=SUM(D9:D21)/13
H22H22=SUM(D9:D22)/14
H23H23=SUM(D9:D23)/15
H24H24=SUM(D9:D24)/16
H25H25=SUM(D9:D25)/17
H26H26=SUM(D9:D26)/18
H27H27=SUM(D9:D27)/19
H28H28=SUM(D9:D28)/20
H29H29=SUM(D9:D29)/21
H30H30=SUM(D9:D30)/22
H31H31=SUM(D9:D31)/23
H32H32=SUM(D9:D32)/24
H33H33=SUM(D9:D33)/25
H34H34=SUM(D9:D34)/26
J9:J21J9=LET(p,MATCH(B2,{"Fortnightly","Monthly","Quarterly","Milestone","Lump Sum"},0),SEQUENCE(CHOOSE(p,13,6,2,2,1),,B3,CHOOSE(p,14,30.41,91,91,182)))
K9:K21K9=J9#+IFS(B2="Fortnightly",13,B2="Monthly",29.41,B2="Quarterly",90,B2="Quarterly",90,B2="Milestone",90,B2="Lump Sum",181)
L9:L21L9=IF($B9<>"",TRANSPOSE(MAX(MIN($K9,$C9)-MAX($J9,$B9)+1,0)),"")
M9:M21M9=IF($B10<>"",TRANSPOSE(MAX(MIN($K9,$C10)-MAX($J9,$B10)+1,0)),"")
N9:N21N9=IF($B11<>"",TRANSPOSE(MAX(MIN($K9,$C11)-MAX($J9,$B11)+1,0)),"")
Press CTRL+SHIFT+ENTER to enter array formulas.
Dynamic array formulas.
Cells with Conditional Formatting
CellConditionCell FormatStop If True
H9:H34Cell Value>=20textNO


However, if I was to change the Payslip Start to the 05/01/2022, it will only count '10 days' but continues to repeat that. I understand that it will always read the same as there are only ever 10 numbers in the row that align, however I am hoping that will be able to recognise somehow that the row beneath it contains some of the date range as well. If the formula works, it should hopefully show (or something like it). i.e.
Row 1: 05/01/2022 - 18/01/2022 has 10 days that fit within the 01/01/2022 - 14/01/2022 but the remaining 4 days fit into row 2 (15/01/2022 - 28/01/2022).

Payslip StartPayslip EndPayment Period StartPayment Period End
5/01/2022​
18/01/2022​
01/01/202214/01/202210
19/01/2022​
1/02/2022​
15/01/202228/01/20224 (the remaining 4 days in row 1 fit into this payment period)
2/02/2022​
15/02/2022​
29/01/202211/02/2022
16/02/2022​
1/03/2022​
12/02/202225/02/2022
2/03/2022​
15/03/2022​
26/02/202211/03/2022
16/03/2022​
29/03/2022​
12/03/202225/03/2022
30/03/2022​
12/04/2022​
26/03/202208/04/2022
13/04/2022​
26/04/2022​
09/04/202222/04/2022
27/04/2022​
10/05/2022​
23/04/202206/05/2022
11/05/2022​
24/05/2022​
07/05/202220/05/2022
25/05/2022​
7/06/2022​
21/05/202203/06/2022
8/06/2022​
21/06/2022​
04/06/202217/06/2022
22/06/2022​
5/07/2022​
18/06/202201/07/2022

Counting the individual days will be important as if a payment period end durings the middle of the week (for example), we would then need to work out the daily rate of hours and times that by the number of days actually completed in the payment period. I am thinking that I will need to extend the columns in J and K to include all of the possibles date combinations, but I thought I would ask if it could be done first?

Thank you all so much!
Sorry! I forgot to add - I tried this technique and thought it might be a winner, but it just doesn't carry right either (like the above max/min): Count overlapping days in multiple date ranges
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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