Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Calculate number of active employees per month

I have the following employee data in a table called StaffDetailsTbl on a sheet called Staff Details:

Employee List

I have another sheet with the following monthly sequence:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

In B4 I have the following code to calculate the numbers of active monthly staff:

=LET(set, StaffDetailsTbl, starts, INDEX(set,,5), ends, INDEX(set,,6), SOMs, $B$1#,
 BYCOL(SOMs, LAMBDA(SOM, LET(EOM, EOMONTH(SOM,0),
  SUMPRODUCT((starts <= EOM) * (ends >= SOM))
 )))
)

However, as seen in the image above, it’s giving incorrect numbers. This is because it doesn’t account for the Employment End Date being empty, so only counts Dave. Is there a way I can modify this formula to include the employee in the count after their Employment Start Date if there’s no Employment End Date?

The data used for the StaffDetailsTbl is:

Employee Employment Start Date Employment End Date
Bob 01/11/2019
Dave 01/11/2019 20/03/2020
Wesley 01/12/2019
Peter 01/12/2019
Jack 01/12/2019
Richard 01/12/2019
Rodney 01/12/2019

>Solution :

I assume when the employment end date is left blank, the headcount shall be continued for that person indefinitely.

Without trying to make it elegant, try the following adjustment:

=LET(set, StaffDetailsTbl, starts, INDEX(set,,5), ends, INDEX(set,,6), SOMs, $B$1#,
 BYCOL(SOMs, LAMBDA(SOM, LET(EOM, EOMONTH(SOM,0),
  SUMPRODUCT((starts <= EOM) * ((ends >= SOM) + ISBLANK(ends)))
 )))
)

So instead of only multiplying with (ends >= SOM), you multiply with ((ends >= SOM) + ISBLANK(ends)) which is either 1 or 0 and shouldn’t be able to be 2, because when (ends >= SOM) is TRUE, it cannot be blank so the second statement ISBLANK(ends) will then be FALSE, and vice versa.

Note: in case the end dates are actually not truly blank but just an empty string (because of a formula), then instead of ISBLANK(ends) use LEN(ends)=0.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading