Sorting Multiple Fields


While sorting on one field is useful, most reports require multiple sorting. In multiple field sorts, Crystal Reports first sorts records from the first sort field. Then, when two or more records have the same value in the first sort field, Crystal Reports sorts the records based on the value of the second sort field.

There is no limit to the number of sorted fields that a report may contain. However, a report will take longer to generate if it contains numerous sorting fields.

To get an idea of how multiple sorting works, try the following example. Continue using the report that you created earlier in this chapter.

  1. Select Report, Record Sort Expert from the menu bar.

  2. Select the following fields.

    Add them to the Sort Fields list box. These will appear after the Product Type Name field you've already created.

    • Product Name (from the Product table)

    • Units in Stock (from the Purchases table)

  3. Press the Add button (>) to add these fields.

  4. Mark the Product Name field as Ascending and the Units in Stock field as Descending.

    You can do this by first left-clicking on the field (when it's in the Sort Fields list box) and then checking the appropriate Sort Direction option button. Figure 8-6 displays what your screen should look like.

    click to expand
    Figure 8-6: Defining multiple sorting with the Record Sort Expert

  5. Press the OK button.

    Figure 8-7 displays the results of your work.

    click to expand
    Figure 8-7: A report with multiple sorting functionality

    You'll notice the report data display in the following sorted order:

    • The Product Type Name field sorts first, alphabetically fromAtoZ.

    • The Product Name field sorts second, alphabetically fromAtoZ.

    • The Units in Stock field sorts third, numerically from large to small.

Changing Sorting Order

To change the sorting order of your records, you can use the Up and Down arrow buttons located within the Record Sort Expert. Perhaps you'd like the Units in Stock field to sort before the Product Name field.

Perform the following steps to change the order in which multiple fields sort within your report:

  1. Select Report, Record Sort Expert from the menu bar.

  2. Select the Units in Stock field located in the Sort Fields list box.

    This field is located in the Product table and is now highlighted.

  3. Press the Up arrow button above the Sort Fields list box, as shown in Figure 8-8.

    click to expand
    Figure 8-8: Changing the sorting order with the Record Sort Order dialog box

    You'll now see this field move before the Product Name field. The report will now sort records by Units in Stock and then Product Name.

If for some reason you don't like the result of your sort, you can use the Undo feature (either from the menu bar or Standard toolbar). The Undo feature will return your report to the way it was before you entered information in the Record Sort Expert.

Removing Sorts

Removing sorting functionality from a field is as easy as adding sorting to your reports.

To remove a sort, perform the following steps:

  1. Select Report, Record Sort Expert from the menu bar.

  2. Select the field from which you wish to remove sorting. You'll select this field within the Sort Fields list box.

    In this example, select the Units in Stock field from the Sort Fields list box. This field is located within the Product table.

  3. Once the field you wish to remove is highlighted, press the Remove button (<) in the Record Sort Order dialog box.

    The sorting field is removed, as shown in Figure 8-9.

    click to expand
    Figure 8-9: Removing sorting fields with the Record Sort Expert

The field is removed from the Sort Fields list box. As a result, the Units in Stock records are no longer sorted within your report (once you press the OK button).




Mastering Business Analysis with Crystal Reports 9
Mastering Business Analysis with Crystal Reports 9 (Wordware Applications Library)
ISBN: 1556222939
EAN: 2147483647
Year: 2004
Pages: 177
Authors: Chris Tull

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net