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.

Formatting Groups

The default layout for groups is that they print one after the other. When a group footer is printed, the subsequent group's header is printed right after it. Some report requirements require changing this default behavior. For example, an invoicing report is designed such that it is grouped by client and each client gets their own invoice. For this report you will put the client information in the group header section and force the group header to be printed at the top of a new page. The summary values appear at the bottom of the page. The group footer is set to always print at the bottom of the page.

The formatting options for groups are in the Section Expert. The Section Expert is discussed in detail in Chapter 8 but for now we are going to look at which options are beneficial for using with groups.

To get to the Section Expert dialog box, right-click on the group section and select Section Expert. This opens the Section Expert dialog box which lists all the sections along the left side and the section properties are listed to the right. The properties of interest here are Print at Bottom of Page, New Page Before, New Page After, Reset Page Number After, and Keep Together.

Print at Bottom of Page

This forces a section to always print at the bottom of the page even if the detail records stop printing in the middle of the page. This is commonly set for the Group Footer section. It is useful for reports that print summary information (sub-totals, disclaimers, logos, etc.). It is also useful for form letters where the bottom of the page must have exact placement.

New Page Before / New Page After

These two properties are used to force the groups onto individual pages. This is so that you can split the reports apart and distribute them independently. For example, a report grouped on Employee Id can be broken apart and each employee can be given their own report without seeing any information about the other employees.

You can either set the New Page Before property for the Group Header or set the New Page After property for the Group Footer. Both give you the same results of splitting the groups onto separate pages. The only problem is that sometimes these options cause a blank page to be printed either at the beginning of the report or at the end of the report. I address this more fully in the Advanced Tutorials section because it requires writing formulas.

Reset Page Number After

This sets the page number back to 1 after the Group has been printed and is usually associated with the Group Header. It insures that the page number for each group starts at 1. Just like the New Page Before property, this is useful for reports that are separated and distributed.

Keep Together

The Keep Together property forces a section to stay on the same page. For example, if the Group Header has the Keep Together property enabled and the entire header can't fit on the page, then it will be started at the top of the next page. The important thing to note is that this only applies to an individual section and it won't take other sections into account.

The Keep Together property may cause a little confusion because there is another property which has similar characteristics and also has a similar name. It is the Keep Group Together property. Let's look at what each property does and how they differ.

The Keep Group Together property looks at the entire group (its header, details and footer) and tries to keep them on the same page. If the entire group can't fit on the remainder of the current page, then the group is started at the top of the next page. This is clearly different than the Keep Together property because it only applies to a single section and the Keep Group Together property looks at multiple sections.

It's important to note that the Keep Group Together property is in a totally different dialog box than the Keep Together property. The Keep Group Together property is in the Change Group Options dialog box (select Report | Group Expert | Options).

There are some rules associated with the Keep Group Together property. If a group starts in the middle of a page and it can't be fully printed by the end of the page, then it starts printing at the top of the following page. If a group requires more than a full page to print, then it will start printing at the top of the following page and continue onto the next page. The Group Header will not be printed on the additional pages unless the property Repeat Group Header on Each Page is set (also in the Change Group Options dialog box).


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