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.
Reports can be sorted on a single field or on multiple fields. Sorting on multiple fields is only useful when the sort field has duplicate values in it. To resolve which one should be listed first, the value in the second field is used to resolve the conflict. An example of this type of report is an employee report that sorts by name. The first sort field is the last name. When there are duplicate last names, the second sort field, the first name, is used. When sorting on multiple fields, you have to specify the order that the fields get sorted in.
To select a field for sorting, either drag and drop it onto the Sort Fields window on the right or click on the arrow buttons to move it over. The order in which you add the fields determines which one gets priority in the sort order. The first field listed becomes the primary sort field. The next field is the secondary field, and so on. When there are duplicate values in one of the fields, then the next field on the list is used to resolve the conflict. This continues for all the sort fields whenever there are duplicates. If a field has a duplicate value without another field after it, then the one that gets listed first isn't always predictable.
The bottom of the dialog box is where you set whether the field is sorted in ascending or descending order. There are two radio buttons that set the sort order and only one can be selected at a time. Since there multiple fields can be shown in the Sort Fields list and there is only one place to set the sort order, both radio buttons apply to the currently selected field. To set the sort order of a field, first click on the field you want and then click on the sort order.
Let's look at the example sort order shown in Figure 3-c. The primary sort field is Country. The secondary field is Region and this is followed by the Customer Name.
Figure 3-c. Sorting records on Country, Region and then Customer Name.
The report first lists all the countries that start with the letter "A". The country Australia has duplicate values, so the report performs a secondary sort on the Region field. The region New South Wales is duplicated so the final sort order is by Customer Name.If you later determine that you need to change the sorting order, modify it using the same steps mentioned earlier.
To read all my books online, click here for the Crystal Reports ebooks.