Sorting Records

Objective

After completing this lesson, you will be able to sort records in a report.

Record Sorting Methods

See the following scenario discussing the sorting, grouping, and summarizing of data.

In a modern office with several people working in the background, two men are focused on a computer screen while discussing data organization and report summaries, with speech bubbles illustrating their conversation about using groups and inserting summaries for subtotals and grand totals.

These grouping options are shown in the following screenshots.

The image displays two side-by-side screenshots of a Change Group Options dialog box from a software interface, where the left panel shows settings under the Common tab for sorting and grouping report records by Customer.Country with options for ascending, descending, specified, or original order, and the right panel shows the Options tab allowing customization of group names by selecting fields or formulas, with additional checkboxes to keep groups together, start new pages after a certain number of visible groups, and repeat group headers on each page, all within a white window featuring OK, Cancel, and Help buttons at the bottom.
The image displays two side-by-side screenshots of an Insert Summary dialog box from a software interface, where the left screenshot shows the Calculate this summary dropdown menu expanded to highlight the Maximum option selected for summarizing the Customer.Customer Name field, while the right screenshot shows the same dropdown menu expanded further to reveal multiple summary calculation options such as Maximum, Minimum, Count, Distinct count, Mode, Nth largest, Nth smallest, and Nth most frequent, with the dialog boxes containing additional settings for summary location and options, set against a neutral background.

Sorting Records

Once you have selected the records to print and positioned them on your report, you will likely want to sort them in a meaningful sequence. For example, you may want to sort them in alphabetical order or from highest to lowest sales. If you do not specify a sort order, Crystal Reports displays the records in their natural order, that is, the order in which they appear in your database.

The image shows a Record Sort Expert dialog box from a data management software, featuring two main panels: the left panel listing hierarchical available fields such as Customer.Country, Customer.Customer Name, and database-specific fields under XTREME (ODBC (RDO)), and the right panel displaying selected sort fields Customer.Country, Customer.Last Year's Sales, and Customer.Customer Name with a Sort Direction option set to Descending, accompanied by actionable buttons labeled OK, Cancel, and Help at the bottom, indicating a user interface for configuring data sorting preferences.

Each field in the Sort Fields list can be assigned a sort direction in ascending or descending order independently. For example, you could sort your list by Region in alphabetical order, then by company in descending order of Last Year Sales.

Sort Control

A sort control allows the users to choose a sort direction without refreshing information from the database.

The image displays a software interface titled Record Sort Expert featuring two main panels: on the left, an expandable list of available fields categorized under Report Fields and XTREME (ODBC (RDO)) with the Customer folder expanded to show related fields; on the right, a Sort Fields panel listing three selected fields—Customer.Country, Customer.Customer Name, and Customer.Last Year's Sales—in order, accompanied by radio buttons below to choose the sort direction (currently set to Ascending), and action buttons labeled OK, Cancel, and Help at the bottom, conveying a functional setup screen for sorting database records.

Users can sort the fields by clicking the sort arrows that appear beside the text object. The report promotes the selected field temporarily to the top of the sort order. When a second Sort Control is used, the first is returned to its original position in the sort order and the second is promoted to the top sort.

Note

To enable a Sort Control on a field, that field must be included in the Sort Fields list first.

Removing a Sort Control

To remove a sort control, choose Not Interactive.

The Sort Control is removed from the report.

Watch this video to see how to implement interactive sort controls in a report.

Sort Controls Considerations

Benefits of Sort Controls

A Sort Control is useful for the following reasons:

  • It allows users to sort report data for further analysis without leaving the canvas of the report.

  • It eliminates processing demand on the database.

  • It reduces the time users spend waiting for data to be sorted.

  • It allows users to sort fields in the report even if they do not have a connection or rights to access the database at the time of viewing.

Sort Control Considerations

When planning to include a Sort Control in your report, it is important to consider the following points:

  • Sort controls apply across an entire record set; you cannot sort only one group.

  • Sort controls cannot be used in sub-reports.

  • Sort controls cannot be created within a cross-tab or an OLAP grid.

  • The use of sort controls causes any open drill-down tabs to close (a warning prompt alerts users).

Summary

  • You can order records in a meaningful sequence, like alphabetical or numerical order, with each field sortable independently in ascending or descending order.
  • Sort Control allows users to sort data interactively and temporarily without refreshing the database.
  • Sort Control applies to entire record sets, cannot be used in sub-reports or specific objects like cross-tabs, and closes open drill-down tabs.