[Tutorial] Simple sorting

Forum rules
No question in this section please
For any question related to a topic, create a new thread in the relevant section.
Post Reply
User avatar
robleyd
Moderator
Posts: 5055
Joined: Mon Aug 19, 2013 3:47 am
Location: Murbko, Australia

[Tutorial] Simple sorting

Post 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
Last edited by robleyd on Thu Jun 20, 2019 2:46 pm, edited 1 time in total.
Reason: Change subject
Cheers
David
OS - Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.2.1.2; SlackBuild for 24.2.1 by Eric Hameleers
User avatar
MrProgrammer
Moderator
Posts: 4894
Joined: Fri Jun 04, 2010 7:57 pm
Location: Wisconsin, USA

Re: [Tutorial] Simple sorting

Post 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.
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.6.3, iMac Intel.   The locale for any menus or Calc formulas in my posts is English (USA).
Post Reply