Sorting Data

docs.kde.org
Search

Sorting Data

In the simple example shown below, the data consists of the names and countries of a number of mountains together with their height above sea level. KSpread can sort data such as this in different ways.


Screenshot of sorted data

We may want the data sorted so that the names are in alphabetical order. To do this select the area containing the data (A2:C7 in this case) and choose Sort Increasing or Sort Decreasing from the Data menu. (Snapshot doc: <before> <after>)

Sorting is done alphanumerically, and is case sensitive, numbers coming before upper case letters which come before lower case letters, so that cells containing the entries Cat, bar,77 and Bat would be sorted into the following order: 77 Bat Cat bar.

The Sort Increasing and Sort Decreasing options from the Data menu options sort the data according to the contents of the cells in the left column of the selected area. For more complex sorting select Data->Sort... to bring up the Sort dialog box.

Using the Sort criteria page of this dialog box you can choose which column of the data is to be used as a primary sort key and, if you wish, other columns to be used as secondary and tertiary keys. Using the example in the above screenshot, choosing column B as the first key and column C as the second would sort the data by country and, for each country, by height.

The Options page lets you sort by row instead of by column and allows you to sort using the order of items in a custom list such as January, February... instead of alphanumerically.

KSpread can also place the results of a sort into a different area of the sheet, or even into a different worksheet, rather than overwriting the original data. To do this enter the top left cell reference of the target area into the Starting cell: text box in the Options page. The cell formats will also be copied to the new area if you check the Copy layout box. If you check the First row contains header box data in the first row will be copied directly to the first row of the target area without being included in the sort operation.

KDE Logo