
The SORT function in Google Sheets returns a sorted copy of a range and keeps it sorted when the data changes. The basic form is =SORT(A2:C20, 2, TRUE), which sorts the table by column 2, from smallest to largest. This guide shows how to sort by one or several columns, sort in descending order, sort a filtered or unique list, set a custom order and fix the common errors. All sample data is made up.
SORT syntax
=SORT(range, sort_column, is_ascending, [sort_column2, is_ascending2, ...])
- range is the data to sort. Leave the header row out.
- sort_column is the column to sort by, as a number inside the range (1 is the first column of the range).
- is_ascending is TRUE for A to Z or small to large, and FALSE for the reverse.
You can add more pairs of sort column and order to break ties.

Sort a table by one column
Say the table A2:C20 holds Name, Region and Sales. To sort by Sales, the third column, from largest to smallest, type this in an empty cell:
=SORT(A2:C20, 3, FALSE)
The sorted table spills into the cells below and to the right. Those cells must be empty. The original data does not move, which is the main difference from the menu command Data, then Sort range, that rearranges the cells themselves.
Sort by two columns
To sort by Region from A to Z and then by Sales from largest to smallest inside each region:
=SORT(A2:C20, 2, TRUE, 3, FALSE)
Sheets sorts by the first pair, and uses the second pair only when the first values are equal.

Sort a filtered list
SORT works with other functions, because it accepts any range or array. To list only the East rows, sorted by sales:
=SORT(FILTER(A2:C20, B2:B20="East"), 3, FALSE)
See our FILTER function examples for more conditions you can use inside it.
Sort a unique list
To get a sorted list of the different values in a column, nest UNIQUE inside SORT:
=SORT(UNIQUE(B2:B20))
When you leave out the other arguments, SORT uses the first column in ascending order. The details of the inner function are in our UNIQUE function examples.
Sort in a custom order
Alphabetical order is wrong for labels such as High, Medium and Low. Build the order with MATCH:
=SORT(A2:C20, MATCH(B2:B20, {"High","Medium","Low"}, 0), TRUE)
MATCH gives each row a position number from your list, and SORT uses those numbers as the sort key. The sort key must have the same number of rows as the range. Test this on a small sample first, since a label that is not in your list returns an error.

Get the top 5 with SORTN
SORTN returns only the first n rows of a sorted result:
=SORTN(A2:C20, 5, 0, 3, FALSE)
The arguments are the range, the number of rows, the way ties are handled, the sort column and the order. A tie mode of 0 shows exactly 5 rows even when there are ties.

Keep the header row
SORT does not know about headers. If you include the header, it is sorted with the data. Type the headers in the row above and start the formula below them. Or use a combined array: ={A1:C1; SORT(A2:C20, 3, FALSE)}.
Fix common SORT errors
- #REF! "Array result was not expanded". Cells in the way are not empty. Clear them.
- Wrong order. The sort column number counts from the first column of the range, not from column A.
- Numbers sort like text. Numbers stored as text sort differently. Convert them to real numbers.
- Blank rows at the end of a big range. Wrap the range in FILTER to drop blank rows, or keep the range exact.
Questions and answers
What is the difference between SORT and Data, then Sort range?
SORT is a formula that leaves the source alone and updates automatically. The menu command changes the source cells once.
Can I sort by a column that is not in the range?
Yes. Instead of a column number, give a range of the same height. For example, =SORT(A2:A20, B2:B20, TRUE) sorts the names by the values in column B.
Does SORT work in Excel?
Yes, Excel 365 and Excel 2021 have a SORT function, but its arguments differ. Excel's version uses a sort index and an order of 1 or -1, so do not copy a Sheets formula straight across.
How do I sort a pivot table in Google Sheets?
Use the sort order options inside the pivot table editor. The SORT formula is for ordinary ranges.
