Chapter 3 - Sorting and Grouping


Being able to sort records in either ascending or descending order is a fundamental reporting skill. Sorting makes it easy for a user to quickly find a particular piece of data buried within a large report. This chapter has ten tutorials that quickly get you up to speed on every aspect of sorting and grouping data.

Become a Crystal Reports expert with the authoritative resource available. The tuturials and tips in this book will take your skills to the next level.
Buy at

This is an excerpt from the book Crystal Reports Encyclopedia. Click to read more chapter excerpts.

Running Totals Compared to Summary Fields

Running totals have similar functionality to summary fields, and they can also be duplicated with formula fields. This can cause some confusion as to when you should use a running total, a summary field, or a custom formula field. Each of these has its unique characteristics that you need to be familiar with to make the best choice.

Summary fields are an easy way to summarize data outside of the Details section. For example, you can put subtotals in the Group Footer and put a grand total in the Report Footer. But you wouldn't want to put either of these fields in the Details section.

Both Summary fields and Running Totals have a limitation that if the report suppresses data, then the summary calculation will include the records that don't get printed. It will show an incorrect value. This is because the summary field and running total is calculated without any knowledge of the conditional formatting formula within the Suppress property. They can't take into account which fields don't get printed.

To get around this limitation, you can create a running total field that evaluates based on a formula and this formula uses the same logic as the conditional formatting formula for the Suppress property. For example, assume the report only wants to show records where the Region field is equal to "West". The Suppress property would have the following conditional formula:

Formula = {Customer.Region} <> "West"

Any records where the Region isn't "West" are suppressed. To make the running total field calculate properly you have to modify it so that it only gets evaluated for the records that do get displayed. In the Evaluate area you would set the option Use a Formula and enter the following formula:

Formula = {Customer.Region} = "West"

Thus, if the Region is "West" then the value is included in the running total field. As an example of this, the report in Figure 3-ij is the same report as the last example. It suppresses some of the records from printing. The grand total field in the left column is a summary field that was added by right-clicking on the Order Amount field and selecting Insert Grand Total. The grand total in the right-most column is a running total field that sums the order amount. The running total field is evaluated using a formula that matches the suppress formula. It is only evaluated for records that get printed.

Figure 3-ij. Summary field incorrectly calculates the grand total.

You can see that the grand total that is calculated with the summary field is much larger than the running total that uses a formula. The summary field is including records that weren't printed on the report.


To read all my books online, click here for the Crystal Reports ebooks.