Count months in which an employee is active during a financial period

Surtsey

New Member
Joined
Jun 13, 2023
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Dear all,

I have spent my last couple of days unsuccessfully trying to find out an Excel formula hence I am turning to this Forum's wisdom.
NOTE: I installed and tried to use XLS2BB add-in but I cannot bypass the macro-locking.

Based on the start/end dates of an employee, I need to count the number of partial months in which the employee was active during a given reporting period.
1) I have four dates in total as shown in the image below:
- Financial Period Start and End Date;
- Employee Start and End Date.

Mr_Excel_NoMonthsActiveWithinPeriod.png


With a simple IF Formula in D6 and E6, I was able to calculate the number of complete (nor partial) months as follows:
Formula in cell D6:
Excel Formula:
=IFERROR(IF(B6<$B$2,DATEDIF($B$2,IF(C6<$C$2,C6,$C$2),"m")+1,DATEDIF(B6,IF(C6<$C$2,C6,$C$2),"m")+1),0)
Formula in cell E6:
Excel Formula:
=IFERROR(IF(B6<$B$3,DATEDIF($B$3,IF(C6<$C$3,C6,$C$3),"m")+1,DATEDIF(B6,IF(C6<$C$3,C6,$C$3),"m")+1),0)

The problem arises when the start/end dates of employee or financial reporting does not coincide with the 1st day of the month. If the example above:
* For employee 1, the "Months active within FP2" should be 11.5 instead of 12; and
* For employee 2, the "Months active within FP2" should be 10.17 instead of 11.

I hope I was able to depict my issue correctly. Thanks a lot in advance!
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
It helped, Peter_SSs, thank you 🔝

Below the file:
MR Excel.xlsx
ABCDE
1Financial PeriodStart dateEnd date
2FP101/06/202131/05/2022
3FP201/06/202231/05/2023
4
5
6EmployeeStart DateEnd DateMonths active within FP1Months active within FP2
7Janusz Cebula01/01/202116/05/202312.0 months12.0 months
8James James26/07/202130/06/202311.0 months12.0 months
Personnel SAL_Jan-Jun'23
Cell Formulas
RangeFormula
D7:D8D7=IFERROR(IF(B7<$B$2,DATEDIF($B$2,IF(C7<$C$2,C7,$C$2),"m")+1,DATEDIF(B7,IF(C7<$C$2,C7,$C$2),"m")+1),0)
E7:E8E7=IFERROR(IF(B7<$B$3,DATEDIF($B$3,IF(C7<$C$3,C7,$C$3),"m")+1,DATEDIF(B7,IF(C7<$C$3,C7,$C$3),"m")+1),0)



The problem arises when the start/end dates of employee or financial reporting does not coincide with the 1st day of the month. If the example above:
* For employee 1, the "Months active within FP2" should be 11.5 instead of 12; and
* For employee 2, the "Months active within FP2" should be 10.17 instead of 11.

I hope I was able to depict my issue correctly. Thanks a lot in advance!
 
Upvote 0
First, you can shorten your existing formulas to
Excel Formula:
=IFERROR(DATEDIF(MAX(B7,$B$2),MIN(C7,$C$2),"m")+1,0)

On your issue, this just seems to be a limitation of the DATEDIF() function, so you'll probably have to replace your existing formula with the more complicated one you used to determine what they should be (though I got 10.19 for employee 2). If your version supports it, I'd probably pursue the LET() function for this.
 
Upvote 1
Not sure exactly how you want to calculate the decimal part or how accurate it needs to be, but see if this is any use.

BTW, Welcome to the MrExcel board!

Surtsey.xlsm
ABCDE
1Financial PeriodStart dateEnd date
2FP11/06/202131/05/2022
3FP21/06/202231/05/2023
4
5
6EmployeeStart DateEnd DateMonths active within FP1Months active within FP2
7Janusz Cebula1/01/202116/05/20231211.5
8James James26/07/202130/06/202310.1666666712
9abc28/05/202314/06/202300.1
Sheet1
Cell Formulas
RangeFormula
D7:D9D7=LET(s,MAX(B$2,B7),e,MIN(C$2,C7),m,DATEDIF(s,e,"m"),d,DATEDIF(EDATE(s,m),e,"d"),IFERROR(m+d/30,0))
E7:E9E7=LET(s,MAX(B$3,B7),e,MIN(C$3,C7),m,DATEDIF(s,e,"m"),d,DATEDIF(EDATE(s,m),e,"d"),IFERROR(m+d/30,0))
 
Upvote 1
Solution
Not sure exactly how you want to calculate the decimal part or how accurate it needs to be, but see if this is any use.

BTW, Welcome to the MrExcel board!

Surtsey.xlsm
ABCDE
1Financial PeriodStart dateEnd date
2FP11/06/202131/05/2022
3FP21/06/202231/05/2023
4
5
6EmployeeStart DateEnd DateMonths active within FP1Months active within FP2
7Janusz Cebula1/01/202116/05/20231211.5
8James James26/07/202130/06/202310.1666666712
9abc28/05/202314/06/202300.1
Sheet1
Cell Formulas
RangeFormula
D7:D9D7=LET(s,MAX(B$2,B7),e,MIN(C$2,C7),m,DATEDIF(s,e,"m"),d,DATEDIF(EDATE(s,m),e,"d"),IFERROR(m+d/30,0))
E7:E9E7=LET(s,MAX(B$3,B7),e,MIN(C$3,C7),m,DATEDIF(s,e,"m"),d,DATEDIF(EDATE(s,m),e,"d"),IFERROR(m+d/30,0))

Hi Peter_SSs,

1) Thanks a lot for the welcome!
2) The LET formula you have produced is absolutely PERFECT - thanks a million to you (and to levipe) for the great help. I owe you a coffee (to say the least).
 
Upvote 0
You're welcome. Glad we were able to help. Thanks for the follow-up. :)
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,262
Members
452,627
Latest member
KitkatToby

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