Print Page | Close Window

years of service formula in crystal reports 2008

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Report Design
Forum Discription: The best way to design a report and problems you have encountered
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=12479
Printed Date: 14 May 2024 at 2:27pm


Topic: years of service formula in crystal reports 2008
Posted By: bayhr
Subject: years of service formula in crystal reports 2008
Date Posted: 02 Mar 2011 at 9:56am
I want to create a formula to have years of service (i.e. 5, 10, 15, 20 years etc...) for employees. Below is a formula that was used. I am not an expert with crystal reports. However, I want to create a formula and to also set a parameter so that the parameter prompt will be set in a way that the report will only pull employees with say 5, 10, 15, etc years of service. 
 
 
Service Year Formula used:
 
//When running this report, you must input a Service Recognition Year parameter.  For example, if the
//current date is November 17, 2005 and you want to recognize employees with five years of completed
//service at a luncheon in Feb. 2006 , then you would input a Year parameter of 2000 (ie. 2000 = Year 0, 2001 = Year 1,
//2002 = Year 2, 2003 = Year 3, 2004 = Year 4, 2005 = Year 5).  The rationale is that employees must complete at least
//five full years of service or more.  For example, if someone is hired on Dec. 12, 2000, then they haven't worked a full year
//until Dec. 12, 2001.
//Dec. 12, 2000 - Dec. 12, 2001 - one year
//Dec. 12, 2001 - Dec. 12, 2002 - two years
//Dec. 12, 2002 - Dec. 12, 2003 - three years
//Dec. 12, 2003 - Dec. 12, 2004 - four years
//Dec. 12, 2004 - Dec. 12, 2005 - five years
//Record Selection criteria says only show people either if the year of their Hire Date is equal to the
//year of Year parameter (ie. Year parameter = 2000 Hire date = October 18, 2000) or if the year of their
//rehire date is equal to the year of the Year parameter (ie. Year parameter = 2000 Hire date = July 2,
//1980 Rehire Date = April 28, 2000).

//Calculates the Service Recognition year.  For example, if you run the report on November 17, 2005, then
//the current year (@Current Year) is 2005.  And, when you run the report and choose the Parameter year
//to be 2000, then the Service Recognition Year is 2005 - 2000 = 5 Year Service Award.

//{@Current Year} - mailto:%7b@Parameter - {@Parameter Year to Number}

2008 - mailto:%7b@Parameter - {@Parameter Year to Number}

 
Year Parameter Setting Used:
 
Please enter the Recognition year (YYYY).  This year will be counted as Year 0 (ie. If running the report in Nov. 2005 to celebrate 5 Years of Recognition in Feb. 2006, then enter 2000; where 2000 = Year 0, 2001 = Year 1, 2002 = Year 2, 2003 = Year 3, 2004 = Year 4, 2005 = Year 5).
 
Any help will be very much appreciated as I'm not an expert with crystal reports. Thanks!



Replies:
Posted By: DBlank
Date Posted: 02 Mar 2011 at 10:06am
why not just have then enter a total number of years '#ofyears' as the parameter and use a dateadd as your select statement
table.hiredate<dateadd('yyyy', - {?#ofyears},currentdate)


Posted By: bayhr
Date Posted: 02 Mar 2011 at 10:14am
can you please further explain using "a dateadd as your select statement."
 
are you saying the table.hiredate<dateadd('yyyy',-{?#ofyears},currentdate) should be the formula that I'll create for years of service? how do I get the dateadd? sorry for my ignorance but I'm not an expert in crystal reports.


Posted By: DBlank
Date Posted: 02 Mar 2011 at 10:20am
dateadd is a function in crystal to add an interval of time to a specific date, in this case a negative number of years to today.
so if you place the formula of
{table.hiredate} <= dateadd('yyyy', - {?#ofyears},currentdate)
in the select expert, your report will only return data rows where the employee was hired on or before (today's date - a paramaters value of years).
It does not per se return a value for total years but rather returns only records that would meet your criteria.
likely you still need to add another condition of
and isnull({table.termdate})
to show only active employees.
Does that help?


Posted By: bayhr
Date Posted: 02 Mar 2011 at 10:29am
It helps but they want the report to actually show employees with service years broken down into 5, 10, 15 years etc... as well as to have a parameter that will prompt users to type in the year.


Posted By: DBlank
Date Posted: 02 Mar 2011 at 10:31am
so they need a parma for a min year and then show all employees that meet that condition ranked by their current tenure/years?


Posted By: bayhr
Date Posted: 02 Mar 2011 at 10:34am
exactly


Posted By: DBlank
Date Posted: 02 Mar 2011 at 10:38am

here is a formula to get the tenure. It is not exactly 100% correct because of leap years but it should be within a day.

datediff('yyyy',{table.hiredate},currentdate) - if datepart('y',currentdate)<datepart('y',{table.hiredate}) then 1


Posted By: bayhr
Date Posted: 03 Mar 2011 at 2:45am
Thnx for the tenure formula. It is greatly appreciated but how do I get the formula to show not only tenure but say 5, 10, 15, 20 yrs etc...when users are prompted by the parameter. How can I set the parameter so that users can type in say 5yrs and it will only show employees with 5 yrs of service etc...Your help will be appreciated.


Posted By: DBlank
Date Posted: 03 Mar 2011 at 3:48am

For clarification,

you want it to always only round to the nearsest completed 5 year mark and allow a user to input any of those 5 year marks and then return all records that are =>than that mark?


Posted By: bayhr
Date Posted: 03 Mar 2011 at 3:53am
well, I want the user to input any of these years: 5, 10, 15, 20 years etc... marks and then return all records with employees having 5, 10, 15 etc...years of service


Posted By: DBlank
Date Posted: 03 Mar 2011 at 4:04am
sorry nut for clarity here... if they enter 5 years do you want them to see only people with 5 or see people with 5, 10, 15 , 20 etc.?


Posted By: bayhr
Date Posted: 03 Mar 2011 at 4:09am

that's ok and thanks for your valuable help.

Well, I want them to be able to not only enter 5 which will show employees with 5 years of service but also they should be able to do the same for 10, 15, 20 etc...which should also pull the employees with those years of service.
 
 


Posted By: DBlank
Date Posted: 03 Mar 2011 at 4:11am
right, but when they do enter 5 should they only see 5 or do they see 5 and above?


Posted By: bayhr
Date Posted: 03 Mar 2011 at 4:14am
they should only see 5.  this should be the same for the other years (i.e. 10, 15, 20, 25, 30 etc...)


Posted By: DBlank
Date Posted: 03 Mar 2011 at 4:21am
ok.
Make a paramater called 'years of service' (or whatever) to allow users to enter the 5/10/15/etc. values.
likley you want this as a
type=number
LOV =static
insert values as 5
then 10 then 15etc. until you get to your max amount
 
go into the select expert and add inthe formula as:
(datediff('yyyy',{table.hiredate},currentdate) - if datepart('y',currentdate)<datepart('y',{table.hiredate}) then 1) - ((datediff('yyyy',{table.hiredate},currentdate) - if datepart('y',currentdate)<datepart('y',{table.hiredate}) then 1) MOD 5)


Posted By: bayhr
Date Posted: 03 Mar 2011 at 5:02am
Thanks very much :) but I'm having an issue deleting old formulas that was placed in the report. will get back to you shortly but in the meantime thanks for all your valuable assistance :)
 
I actually created a new service recognition report using the formulas you provided me and it worked this time around. Thanks a lot for your support. It really helped me a great deal. You're the BEST Smile


Posted By: bayhr
Date Posted: 03 Mar 2011 at 9:26am
Hi there,
 
So I realized a little issue that I thought you could help me with again.
 
example: employee hired date is 8/8/2005. so the year of service should be 6 (i.e. 6 years on 8/8/2011). however, they show up in year 5 and so forth...
 
Is there a way that the prompt will calculate the exact years of service using their hire date? Your help again will be appreciated. Thanks
 


Posted By: DBlank
Date Posted: 03 Mar 2011 at 9:34am
not sure I understand what you want exactly.
datediff('yyyy',{table.hiredate},currentdate) - if datepart('y',currentdate)<datepart('y',{table.hiredate}) then 1
will give you there actual tenure in completed years, although your example if hired on 8/8/2005 will wtill be 5 years as of today because we are using today as our cut off. You can use a param to see whom will hit  a tenure on a future date by replacing currentdate with a param date.


Posted By: bayhr
Date Posted: 03 Mar 2011 at 9:49am

Thnx. Actually, I just thought of it and that should be fine because if an employee has 5.5yrs of service, they aren't necessary at 6yrs of service yet so they'll show up as 5yrs of service...so this is fine. sorry about the confusion.

However, I want to insert a group in the report that will group the employees by their service years (i.e. 5, 10, 15, 20 etc...)


Posted By: DBlank
Date Posted: 03 Mar 2011 at 9:52am
create a formula and use it to group on
totext(
(datediff('yyyy',{table.hiredate},currentdate) - if datepart('y',currentdate)<datepart('y',{table.hiredate}) then 1) - ((datediff('yyyy',{table.hiredate},currentdate) - if datepart('y',currentdate)<datepart('y',{table.hiredate}) then 1) MOD 5)
,0,'') + ' service years'


Posted By: bayhr
Date Posted: 03 Mar 2011 at 10:04am
Thnx but is there a way that the grouping will show say 5, 10, 15 years etc...I tried your formula to group it but it only shows 5 yrs. It doesn't give me the option to select say 5, 10, 15 etc...in the groupings. Pls help?
 
The grouping worked but I want to find out if it's possible to have a select criteria for the years of service to have the option of 5, 10, 15, 20 etc...so that the user can select those from the select criteria which will in turn populate them in the report as groupings. Your help will be great again. Thnx


Posted By: DBlank
Date Posted: 03 Mar 2011 at 10:20am
are you limiting the data in the select expert?
that formula will convert all the rows to there respective grouping of 5-10-15-20-etc.
 


Posted By: bayhr
Date Posted: 03 Mar 2011 at 10:24am

Yes I'm limited them in the select criteria. However, if I go back to change the criteria to either exclude or include other years, I do not see all the years in the dropdown list in the select criteria

example: I selected 5, 10, 15 years but later wanted to exclude 5,10years and to include 15,20years...I don't see them in the select criteria. I only see the ones that I previously selected (i.e. 5,10,15years) Could you please help


Posted By: DBlank
Date Posted: 03 Mar 2011 at 10:29am
how did you create your drop down list?


Posted By: bayhr
Date Posted: 03 Mar 2011 at 10:35am
I meant when restricting the criteria like say service years: is one of, equal to etc...it's supposed to give an option to see all the years that I can either include/exclude at anytime I want, right? but like I said earlier as an example if I include 5,10,15 years etc...and later want to exclude say 10, 15 and rather include 20,25 yrs it doesn't show all the years as an option to include/exclude
 
 


Posted By: DBlank
Date Posted: 03 Mar 2011 at 10:58am
ahhh, you are using the select expert menu.
you need to use the paramters on a report refresh in order for end users to select the data.
Did you create a paramater to use?


Posted By: bayhr
Date Posted: 04 Mar 2011 at 3:00am
I used the parameters on a report refresh but the end user can only select one option (i.e. 5 years of service) at a time, which is ok but they can't select all options (i.e. to include all years of service) at the same time if they want to include all years of service, right? so I tried using the select expert menu to restrict the criteria like say service years: is one of, equal to etc, which I think it's supposed to give an option to see all the years that I can either include/exclude at anytime I want, right? but like I said earlier as an example if I include 5,10,15 years etc...and later want to exclude say 10, 15 and rather include 20,25 yrs it doesn't show all the years as an option to include/exclude.
 
1) Could you please assist if it's even possible to use the parameters on a report refresh to select all years of service at the same time
 
or
 
2) Is it possible to see all the years of service in the select expert menu so end users can either include/exclude the years of service they want to see on the report?
 
Please help and again thanks for all your valuable help. It is greatly appreciated!


Posted By: DBlank
Date Posted: 07 Mar 2011 at 3:37am
create a numeric static parameter with the options you want in the value rows (5/10/15/20/etc.)
In the parameter options set it to allow for multiple values
in your select expert make your select statement use that param with the other formula that gets that 5 year values
{?Param} = (datediff('yyyy',{table.hiredate},currentdate) - if datepart('y',currentdate)<datepart('y',{table.hiredate}) then 1) - ((datediff('yyyy',{table.hiredate},currentdate) - if datepart('y',currentdate)<datepart('y',{table.hiredate}) then 1) MOD 5)


Posted By: bayhr
Date Posted: 07 Mar 2011 at 4:44am
You're really the best of the best :):) Thanks a zillion times for all your valuable help



Print Page | Close Window