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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mlmccCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
DB Reporting Tools

From novice to tech pro — start learning today.