Sorting records

You can sort records into an ascending or descending sequential order and output the results to a new, physically reordered Analytics table. Outputting to an Analytics table is the only output option.

Sorting records is a prerequisite for several Analytics operations. For more information, see Should I do an explicit sort or use Presort?

Sorting can also be a useful analytical operation in itself, bringing patterns and anomalies into focus.

Note

Indexing records is an alternative to sorting them, and in some situations may be a better choice. For more information, see Should I sort or index?

Should I output the entire record or only specified fields?

When sorting, you have the option of including the entire record in the sorted output table, or only specified fields. There are implications associated with each option, summarized below.

The option you choose can also affect sorting speed. For more information, see How to speed up sorting.

Tip

If you want some of the characteristics of outputting by field, but you need the entire record, output by field and select all fields.

Output type Implications
Record
  • The entire record is included in the sorted output table.
  • Computed fields are preserved as computed expressions.
  • Related fields cannot be included. However, the new output table is automatically related to the original child table and you can add fields from the child table to the output table view.
Fields
  • Only specified fields are included in the sorted output table. Key fields are automatically included and do not need to be specified.
  • Computed fields are converted to physical fields and populated with the actual computed values.
  • Related fields can be included. They become permanent physical fields in the output table. The new output table is no longer related to the original child table.

 

Sorting on multiple key fields

You can sort records using one key field, or you can create nested sorting schemes by sorting on multiple key fields – primary key field, secondary key field, and so on. Nested sorting supports mixing data types, and mixing ascending and descending order, across key fields.

Example

You want to sort a transaction table in ascending order on a key date field, and within each date in descending order on a key amount field.

The result below illustrates nested sorting that mixes data type (datetime and numeric), and ascending and descending order.

 

Date field

(ascending order)

Amount field

(descending order, nested)

15 Jan 2011

$2300.00

15 Jan 2011

$1200.00

15 Jan 2011

 $600.00

16 Jan 2011

 $900.00

16 Jan 2011

 $100.00

17 Jan 2011

$4700.00

17 Jan 2011

 $900.00

17 Jan 2011

 $500.00

How to speed up sorting

Sorting very large tables, with millions of records, can be time consuming. Sorting requires a significant amount of system resources and can be slowed down if you are performing other tasks simultaneously.

Improve sorting speed

Two options can improve sorting speed:

  • Output a subset of fields If you need only a portion of the data contained in a record, do not include the entire record in the sorted output table. Select only the fields you need, which in most cases speeds up the sorting process.

    The smaller the subset of fields, as a percentage of the total number of fields, the greater the performance improvement.

  • Increase the memory available for sorting You can allocate a specific amount of memory for sorting, to a maximum of 2000 MB. Go to Tools > Options > Table > Sort Memory, or use the SET SORTMEMORY command.

Additional suggestions

If the amount of time required to sort large tables remains an issue for you, consider:

  • upgrading your computer hardware
  • creating a script to sort data on a scheduled basis overnight

Should I do an explicit sort or use Presort?

Sorting records prior to any of the following operations is either a prerequisite, or recommended:

  • joining tables
  • merging tables
  • summarizing (if you want a single group for each set of identical values in the key field)
  • testing for duplicates
  • testing for gaps

All these operations include the Presort option, which allows you to incorporate a preliminary sequential sorting of records as part of the operation.

If you are performing two or more of these operations on the same table, explicitly sorting the table first, rather than repeatedly using Presort, may be more efficient, especially if the table contains a large number of records.

Verifying that all source records are in the output table

If you are sorting and outputting all the records in a table, you can set a control total on a numeric field to verify that all the records are in fact output to the new table.

You set a control total for a field in the Table Layout dialog box. Once you have sorted and output the records, in the new table select Tools > Table History to compare the input and output control totals. For more information, see Define a physical field.

Steps

You can sort records by one or more key fields in the active table and output the results to a new Analytics table. You can include the entire record in the sorted output table, or only specified fields.

Analytics 14.1 Help