+ Reply to Thread
Results 1 to 13 of 13

Calculate years of service

  1. #1
    Forum Contributor
    Join Date
    02-20-2011
    Location
    Candada
    MS-Off Ver
    Microsoft Office 365
    Posts
    174

    Calculate years of service

    I am looking if there is an Excel formula or macro that can calculate the years of service for each employee based on periods of employment and seniority date. In order for a year to be considered as a year of service, an employee must work a complete calendar year (January 1st through December 31st); otherwise, that period of employment (months) do not count toward someone’s years of service. The problem comes in because we have quite a few employees that have been terminated and rehired. Also, once obtaining the years of service, I am using VLOOKUP to obtain the vacation days from information located on the VacationTable tab. However, I can’t figure out the vacation hours, monthly accrual and daily accrual based on the vacation days.
    Can anyone help me? I've been stuck for a while and can’t get this to work.
    Please refer to attached file for better understanding of what I am trying to accomplish.

  2. #2
    Forum Contributor
    Join Date
    04-07-2009
    Location
    Rowley
    MS-Off Ver
    Excel 2007
    Posts
    326

    Re: Excel formula or macro to calculate years of service for each employee

    This will not answer all you questions, but should give you a start to getting the answers you need.

    In order for a year to be considered as a year of service, an employee must work a complete calendar year (January 1st through December 31st);

    This means your Start Date is always Jan 1st of the year after your date of hire, IE

    Actual Date of Hire is 09/03/1997
    To be considered as years of service, Date is 01/01/1998

    It also means your Termination Date, is always Dec 31st of the year prior to your actual Termination Date, IE

    Actual Date of Termination is 03/22/2003
    To be considered as years of service, Date is 12/31/2002

    So a formula like:

    =IFERROR(DATEDIF(DATEVALUE("01/01/"&YEAR(D3)+1),DATEVALUE("12/31/"&YEAR(E3)-1),"Y"),0)

    Will give you the number of years of service for the Original Hire & 1st Term Date.

    The formula can probably be shortened to something like:

    =IFERROR(SUM(YEAR(E3)-1)-(YEAR(D3)+1),0) but this is untested.

    You will also need to add a check to make sure that there is a Termination Date else the formula does not work.

    If there is no Termination Date, then you are still working, so we use Todays Date, with the TODAY() function
    something like:

    =IF(E3>0,IFERROR(DATEDIF(DATEVALUE("01/01/"&YEAR(D3)+1),DATEVALUE("12/31/"&YEAR(E3)-1),"Y"),0),IFERROR(DATEDIF(DATEVALUE("01/01/"&YEAR(D3)+1),DATEVALUE("12/31/"&YEAR(TODAY())-1),"Y"),0))

    This will have to be repeated 4 times, and then you will need to Total all the results.

    It also means you will need to modify the above formula with another check, to make sure there is a Hire Date.

    So the formula now become something like:

    =IF(D3="",0,IF(E3>0,IFERROR(DATEDIF(DATEVALUE("01/01/"&YEAR(D3)+1),DATEVALUE("12/31/"&YEAR(E3)-1),"Y"),0),IFERROR(DATEDIF(DATEVALUE("01/01/"&YEAR(D3)+1),DATEVALUE("12/31/"&YEAR(TODAY())-1),"Y"),0)))

    To make life a bit easier I would add a Helper Column between each section, and do the calculation for each section, then total everything.

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Excel formula or macro to calculate years of service for each employee

    The OP is on Excel 2003 (notice the left sidebar?) Be sure to adjust your formulas to ones that do not include the IFERROR() function.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    Forum Contributor
    Join Date
    04-07-2009
    Location
    Rowley
    MS-Off Ver
    Excel 2007
    Posts
    326

    Re: Calculate years of service

    As JBeaucaire pointed out, you can't use the IFERROR() function, so try this, which seems to work, and is a bit shorter to boot.

    =IF(D3="",0,IF(E3>0,IF(SUM(YEAR(E3)-1)-(YEAR(D3)+1)>=1,SUM(YEAR(E3)-1)-(YEAR(D3)+1),0),IF(SUM(YEAR(TODAY())-1)-(YEAR(D3)+1)>=1,SUM(YEAR(TODAY())-1)-(YEAR(D3)+1),0)))

  5. #5
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Calculate years of service

    Does that give the right result, though? That formula gives me 4 for the first row of data, shouldn't that be 5 for for the first period of hire (1998,1999,2000,2001,2002 are worked in full)?

    I think you can get the full years with this formula

    =YEAR(IF(E3,E3,TODAY())+1)-YEAR(D3-1)-1

    Extend to this "array formula" for all 4 periods

    =MAX(0,SUM(IF(MOD(COLUMN(D3:J3)-COLUMN(D3),2)=0,IF(D3:J3<>"",YEAR(IF(E3:K3,E3:K3,TODAY())+1)-YEAR(D3:J3-1)-1))))

    confirmed with CTRL+SHIFT+ENTER
    Audere est facere

  6. #6
    Forum Contributor
    Join Date
    04-07-2009
    Location
    Rowley
    MS-Off Ver
    Excel 2007
    Posts
    326

    Re: Calculate years of service

    daddylonglegs,

    You are correct, it's an artifact of the math: 1998 + 4 = 2002

    Have not tried your formula, but this seems to work:

    =IF(D3="",0,IF(E3>0,SUM((YEAR(E3)-1)-(YEAR(D3)+1)+1),SUM(YEAR(TODAY())-1)-(YEAR(D3)+1)+1))

  7. #7
    Forum Contributor
    Join Date
    02-20-2011
    Location
    Candada
    MS-Off Ver
    Microsoft Office 365
    Posts
    174

    Lightbulb Re: Excel formula or macro to calculate years of service for each employee

    Mr. Beaucaire, thanks you for sharing your knowledge with daddylonglegs, xenixman, and me; I appreciate your help with this problem that I am facing. I’d like to take the opportunity to let you know that I am a huge fan of you, and I have used a lot of your work on my everyday life. I feel privileged to have you, daddylonglegs and xenixman here helping me with this problem. However, I don’t understand by what you mean with OP on Excel 2003. I am still learning Excel.

  8. #8
    Forum Contributor
    Join Date
    02-20-2011
    Location
    Candada
    MS-Off Ver
    Microsoft Office 365
    Posts
    174

    Thumbs up Re: Calculate years of service

    Thank you, Mr. daddylonglegs for your time and sharing your knowledge with me. I used your formula: =MAX(0,SUM(IF(MOD(COLUMN(D3:J3)-COLUMN(D3),2)=0,IF(D3:J3<>"",YEAR(IF(E3:K3,E3:K3,TODAY())+1)-YEAR(D3:J3-1)-1))))

    confirmed with CTRL+SHIFT+ENTER
    but I am getting a #VALUE error on Ford, Musco's years of service. Shouldn’t I get in return a value of 4 years of service instead?
    Again, this forum wouldn’t be the same without you guys.

  9. #9
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Excel formula or macro to calculate years of service for each employee

    Quote Originally Posted by Kimston View Post
    ...I don’t understand by what you mean with "OP on Excel 2003"...

    Sorry, that's "forum speak" for "Original Poster". In long hand, "the original poster of the question is using Excel 2003".

  10. #10
    Forum Contributor
    Join Date
    02-20-2011
    Location
    Candada
    MS-Off Ver
    Microsoft Office 365
    Posts
    174

    Re: Excel formula or macro to calculate years of service for each employee

    Thanks Mr. Beaucaire for clarifying it for me. Now that I almost have the years of service, I am using this formula =(N3*8) to get the vacation hours; however, I don't know how would I get the monthly accrual or the daily accrual. Any help would be very appreciating.

  11. #11
    Forum Contributor
    Join Date
    04-07-2009
    Location
    Rowley
    MS-Off Ver
    Excel 2007
    Posts
    326

    Re: Calculate years of service

    I am getting a #VALUE error on Ford, Musco's years of service.

    His first TERM DATE: 11/31/2001 is your problem.
    There are only 30 days in November.

  12. #12
    Forum Contributor
    Join Date
    02-20-2011
    Location
    Candada
    MS-Off Ver
    Microsoft Office 365
    Posts
    174

    Re: Calculate years of service

    Sorry for getting back to you late. Just came back from vacations.
    Thank you, Xenixman for pointing this out. After fixing the date, the #VALUE went away. Any help would be very appreciating if someone can help with figuring out the daily and monthly accrual. Happy New Year to all you!

  13. #13
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Calculate years of service

    I got nothing. I get 5 for the first row, not 6, and the array formula correction I came up with:

    =MAX(0,SUM(IF(MOD(COLUMN(D3:J3)-4,2)=0,IF(D3:J3<>"",YEAR(IF(E3:K3,E3:K3,TODAY())+1)-YEAR(D3:J3-1)))))-2

    Only seems to work for "most" of the rows. Not all. I'll ping some others to take a look.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1