Link to home
Start Free TrialLog in
Avatar of MsLED
MsLED

asked on

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.  
ASKER CERTIFIED SOLUTION
Avatar of Mike McCracken
Mike McCracken

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MsLED
MsLED

ASKER

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;
 

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
Avatar of MsLED

ASKER

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.
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
Avatar of MsLED

ASKER

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.
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
Avatar of MsLED

ASKER

Thank you for your help.