Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conditional Running Totals

Running Totals

Conditional Running Totals

by  HowardHammerman  Posted    (Edited  )
You may run into a situation where you want your Crystal Report to show many records, but to create a total for only some of them. The answer is a conditional running total.

Say, for example, you have a table of employees, and you want to show the entire roster, but you only want to total salaries for those employees with id numbers within a range specified by your users. Your first step is to create a parameter field - perhaps called EmpNum. In the Crystal Create (or Edit) Parameter Field dialog, we'll make our example a string data type, and click on the Range Value(s) radio button.

Now we create a running total - on the Employee_Salary field. It's a sum in the Crystal Create (of Edit) Running Total Dialog. The fun happens in the dialog's Evaluate section.

Click on the Use a Formula radio button. In the Running Total Condition Formula dialog that appears next, enter:

{EMPLOYEE.EMP_NUMBER} in {?EmpNum}.

This means, "OK, Crystal, don't add to my running total unless the employee's Employee Number is within the range that the user has specified." Naturally, you'll want to place your running total on the report - probably in the detail section to see how it works. It's best to sort the report on employee number, too.

When you run the report or refresh data, you'll be prompted for the lower and upper values for the employee number. If you use the samples from our website*, and enter (for example) 3 for the lower and 5 for the upper value, the running total field will be blank until you hit 3010, then will increase by each employee's salary until you hit 5000, and will not change again until the end of the report.

Howard Hammerman, Ph.D.
Hammerman Associates, Inc.
http://www.hammerman.com
800-783-2269
Hammerman Associates, Inc. provide Crystal Reports training,
consulting, course material, utilities and software. Consultants are available throughout North America for short or long-term assignments.
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top