Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Record crossing two groups Post Reply Post New Topic
Author Message
kemigirl
Newbie
Newbie


Joined: 05 May 2009
Online Status: Offline
Posts: 14
Quote kemigirl Replybullet Topic: Record crossing two groups
     Posted: 18 May 2009 at 10:03am
I am creating a report in Crystal XI that is grouped as follows:

Year (2000)
      Employee#      Action Date
      Employee#      Action Date

Year (2001)
      Employee#      Action Date

The employees are grouped by an action date of when they entered a job code.  When I pull the data from the system, there are multiple records that show for almost all the employees.  I only wanted to count each employee once.  My quick original solution was simply to distinctcount the employees to get the number of employees hired in each year.

I was checking my data and realized that my grand total count was one number different from the group counts and what I discovered is that one particular employee, through the course of the mutliple records pulled, has an action date in 2005 and another in 2006.  So the grouping by year is picking this person up in both years.  I only want him to show the first time (in 2005).

I need the report to allow the user to drill down within the year and see all the employees listed in that year.

Is there a way I can sort or group so that each person only shows up once...based on the first date?

Any help is GREATLY appreciated!  I am very new to Crystal, so please forgive me if this is a bad question.
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 18 May 2009 at 3:09pm
The best solution is to exclude the duplication before pulling it into Crystal. Can you create a view to use instead of the table where you can group on the worker and use the minimum (or max if appropriate) on the date field?
IP IP Logged
kemigirl
Newbie
Newbie


Joined: 05 May 2009
Online Status: Offline
Posts: 14
Quote kemigirl Replybullet Posted: 19 May 2009 at 7:41am
Unfortunately, our IT department is less than excited about making a connection to views/queries, since this would be a published report and would be available to others to update/view at any time. 

There's not a way to do a query in Crystal, is there? Outside of the select expert itself?

Is there a way to create a formula to check for distinct employee number throughout the whole report rather than just the group the formula is in? 

Thanks again for your consideration of my questions!
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 19 May 2009 at 8:00am
I am not sure why they are not OK with it unless they are looking to deploy this with a product to a lot of different seperate companys...Using a view is no different than using a table as far as deploying it or security. The only real new risks, as far as I know is creating a view that is so poorly done that it impacts the overall performance of the DB and possibly giving someone new more rights in the DB itself (you to create and alter views).
If you cannot convince them, although if you are going to be working with this DB for report writing much it may be worth a fight, you can use the Command function to write a SQL query in crystal itself.


Edited by DBlank - 19 May 2009 at 8:01am
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 20 May 2009 at 6:29am
another option, not the best, as excluding the dupe at time of selection (DBlank's suggestion) is by far the best (OK, maybe not the best, but what I would do as well) is to create a shared variable.
 
Most of my solutions involved shared variable because they are so versatile.  Any how, create a shared string variable and as the report runs, it will add the employees name or id or whatever is unique to the string with an identifier, but first it will check so that suppression can occur.
 
doesn't sound too clear to me, let's try an example:
this would be the 'equation' in the suppression formula, say for details, but it could be where ever you need to hide the dupe ( you may need it aggregrate calculations as well as suppressed entries are included in things like sums and averages...  how to complicate things...
 
shared stringvar usedID;
 
//this would be for an number...a name wouldn't need the totext call
instr(usedID, "|"+totext({table.numberID},0,"")+"|")
 
I would add a second detail section and put a formula that adds the id, (assuming the suppression is of the detail section) so that they person cannot show up again. so that formula would look like:
shared stringvar usedID:=usedID + "|"+totext({table.numberID},0,"") + "|";
""  //i use the empty string to hide the result of the formula, but if you suppress the whole 'second' detail section, it is not needed.
 
Thinking about it, now, this will remove the duplicate from showing, but it won't adjust the numbers.  There you will either need to create your own counter, or adjust a running total.  DBlank is by far better on the Running Total, as I would use shared variable, as I am already doing a calculation.
 
So I would modify the last formula to be something like:
shared stringvar usedID;
shared numbervar empCount;
 
if instr(usedID,  "|"+totext({table.numberID},0,"") + "|") = 0 then (
 empCount := empCount + 1;
 usedID := usedID + "|"+totext({table.numberID},0,"") + "|";
);
 
""  //i use the empty string to hide the result of the formula, but if you
 
and then for the total you get the simple formula of
shared numbervar empCount
 
place the formula where the distinctcount is, voila (hopefully) everything lines up.
 
If you just want a count of employees and it is ok to see a dupe, remove the suppression, but keep the counter as it is truly a unique count regardless of grouping.
 
HTH
IP IP Logged
kemigirl
Newbie
Newbie


Joined: 05 May 2009
Online Status: Offline
Posts: 14
Quote kemigirl Replybullet Posted: 19 Jun 2009 at 1:44pm
Thank you for sharing these options.  DBlank, as much as I'd like to think my IT dept is awesome and would do all that for me...that is just not the case. Cry  Unfortunately I am not in IT and I am just "helping out" my department, so I haven't been given access to much.

As an update, though, I finally got this to work, and here's how!  I ended up grouping the employee records by employee ID, and used a RT in the detail section that picked up the earliest date for the employee, and ran it through all the multiple records and dumped that date into the group footer, therefore, catching the original date with the employee ID in the footer. Yay!  I then did all my actual calculations and RT's based on the group footers.

It was a very tedious and awful process, but it worked and my boss is very happy.
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum