How do I count the first record in a group and show the result at the end of the report?

I am creating a report in employee # order that groups on employee#.  There may be varying number of records per employee# with amounts to be totaled on the report.  I want a distinct count of the number of employees shown on the report.  I have tried the running total, with change on group and no reset, but I still get the count of all records instead of count of employees.  
MsLEDAsked:
Who is Participating?
 
mlmccConnect With a Mentor Commented:
Try 2 ideas

First
Right click the Employee# field
Click INSERT --> SUMMARY
Select DISTINCT COUNT as the type of summary
Put it in the report footer.

If that doesn't work use a manual method
In the report header
WhilePrintingRecords;
Global NumberVar EmployeeCount := 0;
''

In the group header
WhilePrintingRecords;
Global NumberVar EmployeeCount;
EmployeeCount := EmployeeCount + 1;
''

In the report footer
WhilePrintingRecords;
Global NumberVar EmployeeCount;
EmployeeCount

mlmcc
0
 
MsLEDAuthor Commented:
Thank you for your response.  

The first solution did not give me the expected results.
I tried the second solution and am getting a count higher than I expect.  As long as I have the 'WhilePrintingRecords', does that handle record selection that I have in an if clause?
This is code I have included in the Group Header:

WhilePrintingRecords;
Global NumberVar EmployeeCount;

if {F06146.YNPDBA}in 1 to 49 or
 {F06146.YNPDBA} in 60 to 62 or
 {F06146.YNPDBA} in 65 to 67 or
 {F06146.YNPDBA}in 802 to 803 then
 EmployeeCount:= EmployeeCount + 1;
 

0
 
mlmccCommented:
The WhilePrintingRecords just tells Crystal when to run the formula.  In this case during the PrintingRecords pass (final pass) of building the report.  It is the only pass where variable values are maintain from record to record.

DistinctCount will count 1 for each it finds.  In your case you need to filter further.

What groups do you have?

mlmcc
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
MsLEDAuthor Commented:
The group is on employee number but there may be varying number of records for each employee and some employees excluded based on the parameters passed.
0
 
mlmccCommented:
When you say excluded, the filtering is done in the record selection rather than in the report?
If it being filtered then the counts should be correct.

If you are suppressing then you need to apply that test to the formulas also

mlmcc
0
 
MsLEDAuthor Commented:
Filtering is being done in record selection section.  The code I previously included is used in the amount totals as each record is read.  It doesn't seem that it needs to be included to determine whether an employee is selected.
0
 
mlmccCommented:
What is the group field?  If it isn't employee number then you will still get duplicates.

Is you number higher or lower than expected?

mlmcc
0
 
MsLEDAuthor Commented:
Thank you for your help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.