Page 1 of 1

[Tutorial] Simple sorting

Posted: Thu Jun 20, 2019 12:12 pm
by robleyd
A question appears here occasionally about sorting data in multiple columns - how to retain the relationship between columns when you only want to sort by the data in one column.

The solution is simple; you need to select all the columns, even though you only want to use the information in one column as the basis for your sort.

Let's say I have my entire music collection - all 20 or so songs - listed in a spreadsheet in no particular order. I have three columns, Artist, Song and Year. All well and good, but I want them listed in alphabetical order of artist name. So I select the entire range of song information.
song_sort01.png
Then I go to the menu at the top and select Data | Sort which provides a dialogue box to allow me to define the order in which I want the data sorted. Artist name is in column A, so I choose to sort by column A in ascending order.
song_sort02.png
I click OK and the information in column A is sorted according to my specifications, and data in the other columns retains its relationship to column A.
song_sort03.png
Ah, but although the artists are in order, I'd like to have the songs in chronological order as well, so earlier songs by the same artist are shown before later efforts. So, with the entire data selected as before, I go back to Data | Sort and this time select column A as the primary sort, and column C as secondary sort order. This will sort by artist name, and then by date for that artist.
song_sort04.png
I click OK and I have what I want.
song_sort05.png

Re: [Tutorial] Simple sorting

Posted: Mon Aug 05, 2019 6:33 pm
by MrProgrammer
robleyd wrote:The solution is simple; you need to select all the columns
Even better, select them then use Data → Define Range and give this range a name. Under → More you will usually want ✓ Insert or delete cells and ✓ Keep formatting. Ensure that you have set Contains column labels correctly, then click OK.

After naming the range, when you select a cell in it and use Data → Sort, Calc knows you want to sort this entire range. And, when sorting at a later time, Calc will remember what sort criteria you used and have those values pre-set in the Sort dialog so you can quickly do Data → Sort → OK.