Home > Software engineering >  calculating number of active employees for partial months
calculating number of active employees for partial months

Time:11-10

I have a set of employees on a project and I have the following formula that calculates the number of employees active each month:

=MMULT(SEQUENCE(1,ROWS($A$20#),1,0),($L$1#>=OFFSET($A$20#,0,3,,1))*($L$1#<=OFFSET($A$20#,0,4,,1)))

Where $L$1# is defined by =EDATE(01/01/2020, SEQUENCE(1, 6, 0)) and $A$20# refernces the first entry in a dataset of employees as below:

Employee Role Discipline Start Date End Date
Bob Senior Programmer Programming 12/01/2020 06/05/2020
Dave Mid Level Programmer Programming 01/02/2020 30/05/2020
Peter Senior Programmer Programming 01/01/2020 31/01/2020
Jack Junior Programmer Programming 01/02/2020 30/06/2020
Richard Senior Artist Art 01/03/2020 30/04/2020
Rodney Lead QA QA 01/03/2020 30/06/2020

This formula above will only cope with those employees on a project from the start of the month. I'd like it to increment the number of employees even if they are on it for a single day in the start month so giving the following result:

Jan 20 Feb 20 Mar 20 Apr 20 May 20 Jun 20
Active Staff 2 3 5 5 4 2

I tried modifying the formula to check if the Start Date is between the month start and month end defined by $L$1# but unfortunately this doesn't like the use of $L$1# in the EOMONTH function:

=MMULT(SEQUENCE(1,ROWS($A$20#),1,0),(AND((OFFSET($A$20#,0,3,,1)>=$L$1#),(OFFSET($A$20#,0,3,,1)<=EOMONTH($L$1#,0))))*($L$1#<=OFFSET($A$20#,0,4,,1)))

How would I go about adjusting the above to work with $L$1#?

CodePudding user response:

You can try the following in cell G1:

=LET(set, A2:E7, starts, INDEX(set,,4), ends, INDEX(set,,5), SOMs, G1:L1,
 BYCOL(SOMs, LAMBDA(SOM, LET(EOM, EOMONTH(SOM,0),
  overlaps, FILTER(starts, (starts <= EOM) * (ends >= SOM), 0),
  ROWS(overlaps)
 )))
)

There are multiple ways to achieve the same, for example using SUMPRODUCT or just SUM:

=LET(set, A2:E7, starts, INDEX(set,,4), ends, INDEX(set,,5), SOMs, G1:L1,
 BYCOL(SOMs, LAMBDA(SOM, LET(EOM, EOMONTH(SOM,0),
  SUMPRODUCT((starts <= EOM) * (ends >= SOM))
 )))
)

The main idea is to check for overlap condition of two intervals A, B:

AND(startA <= endB, endA >= startB)

Note: None of the above approaches use OFFSET a sample excel file

  • Related