Sub topic 1
Prepare your data: one table, one header row
Prerequisites
This chapter assumes you can open a Google Sheets file, select cells and ranges such as A2:D100, and enter a simple formula such as =SUM(A1:A10). You should also know how to open the Data menu.
Use one table with one header row
Sorting and filtering work on a contiguous block of rows called a range. Keep one table per sheet, with a single header row in row 1 and one record per row below it. Avoid blank rows or subtotal rows inside the table, because they split the range and cause sorts to stop early or move totals into the data.
Mark the header row
When you sort, Sheets needs to know whether row 1 is a header. If it is, the header stays in place. Select the range, then open Data > Sort range > Advanced range sorting options and tick "Data has header row."
Sort a range or a whole sheet from the Data menu
Select the range you want to sort, then choose Data > Sort range. Pick a column, then choose A→Z or Z→A.
To sort the whole sheet, click a single cell inside the table and choose Data > Sort sheet by column. Use this only when every row on the sheet belongs to the same table.
Sort by more than one column
Use advanced sorting when ties need a second rule. For example, sort by Region A→Z, then by Amount Z→A.
- Select the range.
- Open Data > Sort range > Advanced range sorting options.
- Tick "Data has header row."
- Set the first sort column, then click "Add another sort column" and set the second.
=SORT(A2:D, 1, TRUE, 3, FALSE)This formula returns the rows sorted by Region, then by Amount from largest to smallest, and leaves the source data unchanged.
Why sorting goes wrong: text numbers, dates and blanks
Most unexpected sort results come from data types. Numbers stored as text sort alphabetically, so "100" comes before "9". Dates stored as text sort the same way. Check alignment: numbers and real dates align right by default, and text aligns left.
Blank cells are a separate problem. Sheets places blanks at the bottom of an ascending sort, so a partly filled column can push records out of order when a header is missed.
Use Format > Number to convert text-formatted numbers, or use VALUE() in a helper column.
Exercise:
Exercise
You sort A1:D50 by Amount, but the header row moves into the middle of the data. What setting did you miss, and where do you set it?
Show answer
You did not tick "Data has header row." Open Data > Sort range > Advanced range sorting options and tick it before sorting.