SheetsLessons
Filter & Sort function

SORT function in Google Sheets

SORT returns a sorted copy of a range, ordered by one or more columns, without rearranging the original data. Because it is a formula, the sorted list stays in order as values change or rows are added, which the Data › Sort range menu can't do.

Syntax

=SORT(range, sort_column, is_ascending, [sort_column2, is_ascending2, ...])
range
The data to sort, without its header row.
sort_column
Which column to sort by: a number counting from the first column of range (1, 2, 3…), or a separate one-column range with the same number of rows.
is_ascending
TRUE for A→Z and smallest first, FALSE for Z→A and largest first.
sort_column2, is_ascending2, ...
Optional. More columns to break ties, each with its own direction.

Practice SORT

Task 1 of 4

Sort the whole table (A to C) by sales, highest first. Put the sorted copy in E2.

E2
fx

Tip: while typing a formula, click a cell or drag across cells to insert references. Press Enter to check, and Tab to accept a function suggestion.

SORT examples

Each example below runs against this sample sheet. The results are calculated by the same engine as the practice grid.

ABCDE
1RepRegionProductUnitsRevenue
2AvaWestMonitor12$2,400.00
3LiamEastKeyboard30$1,500.00
4MayaWestMouse45$900.00
5NoahNorthMonitor8$1,600.00
6ZaraEastMonitor15$3,000.00
7OmarWestKeyboard22$1,100.00
Sales by rep
FormulaResultWhat it shows
=SORT(A2:E7, 5, FALSE)
ZaraEastMonitor153000
AvaWestMonitor122400
NoahNorthMonitor81600
LiamEastKeyboard301500
OmarWestKeyboard221100
MayaWestMouse45900
Every row, highest revenue first.
=SORT(A2:B7, 2, TRUE, 1, TRUE)
LiamEast
ZaraEast
NoahNorth
AvaWest
MayaWest
OmarWest
By region, then by name within each region.
=SORT(A2:A7)
Ava
Liam
Maya
Noah
Omar
Zara
With only a range, SORT goes A→Z by the first column.
=SORT(A2:A7, D2:D7, FALSE)
Maya
Liam
Omar
Zara
Ava
Noah
Names ordered by units sold, a column that isn't in the output.
=SORT(UNIQUE(C2:C7))
Keyboard
Monitor
Mouse
An alphabetical list of the products, each listed once.
=SORT(A2:E7, 6, TRUE)#VALUE!Column 6 doesn't exist in a five-column range.

Tips and common mistakes

  • sort_column counts within the range. In SORT(C2:E9, 2, TRUE), 2 means column D, not column B.
  • Leave the header row out of the range or it gets sorted in with the data.
  • Blank rows always sort to the bottom, in both directions, so open-ended ranges like A2:E are safe.
  • Rows that tie keep their original order. Add a second sort column if you need a specific tie-break.
  • To get the top N rows, combine SORT with ARRAY_CONSTRAIN, or use QUERY with order by and limit.

Related functions