I have a table set up with Employee Start Date, Termination Dates and then monthly columns - see image below.
I am trying to calculate the Employee Tenure but based on the following scenarios:
An employee has started within the month or is currently employed and has no termination date - Tenure will calculate as normal with Start Date and reporting month (columns CF, CG etc)
An employee has terminated - Tenure will calculate with Start Date and reporting month until Termination month and then swap to calculation between start and termination date (columns E, F). Once the termination month has passed the tenure will be 0 for that employee. eg. Start 11-Jan-16, Termination 8-Jul-16, Column CF (June) & CG (July) will calculate as normal and Column CH (Aug) should be 0.
Here is an image of my current worksheet set up:
The formula I have currently is:
=IF(OR(CF$2>CurrentReportMonth,$E9>CF$2),0,IF($F9>CF$2,0,IF(OR($E9<=CF$2,$F9<CF$2),DATEDIF($E9,CF$2,"M"),DATEDIF($E9,$F9,"m"))))
cell CF3
, enter this formula and drag over tocell CJ12
to see if this is what you need:=IFERROR(DATEDIF(DATE(YEAR($E3),MONTH($E3)+1,1)-1,MIN($F3,CF$2),"m"),"-")
. I assume you don't want to include the month of hire unless it is the first date of the month but let me know if you use different rules. – ian0411=IFERROR(DATEDIF(EOMONTH($E3,0),MIN(IF(AND($F3>0,CF$2>$F3),EOMONTH($E3,0),$F3),CF$2),"m"),"-")
. Try this and let me know if this is what you are looking for or I can tweak a little bit more. – ian0411