Going Stellar

Home/Google Sheets reference

Google Sheets function · Filter and sort

SORT in Google Sheets: syntax and examples

SORT returns the rows of a range in a new order, by one or several columns, without changing the original data. The result spills into the cells below and to the right of the formula.

Syntax

SORT(range, sort_column, is_ascending, [sort_column2], [is_ascending2])

Arguments

ArgumentTypeRequiredWhat it does
rangerangeyesThe rows to sort. The header row should stay outside.
sort_columnnumberyesWhich column of range to sort by, counted from 1 inside range.
is_ascendingbooleanyesTRUE for A to Z and small to large, FALSE for the reverse.
sort_column2numbernoA second column used to break ties.
is_ascending2booleannoDirection for the second column.

Examples

The examples use this table, starting in A1:

RegionProductUnitsPrice
NorthPen102.5
SouthPen42.5
NorthBook312
EastBook812
SouthLamp530
=SORT(A2:D6, 3, FALSE)

Result:

NorthPen102.5
EastBook812
SouthLamp530
SouthPen42.5
NorthBook312

All rows ordered by units, largest first. The result spills into a block that starts in the formula cell.

Run in a Google Sheet (English US locale) on .

=SORT(A2:D6, 2, TRUE, 3, FALSE)

Result:

EastBook812
NorthBook312
SouthLamp530
NorthPen102.5
SouthPen42.5

Two keys: product A to Z first, then units from large to small inside each product.

Run in a Google Sheet (English US locale) on .

=SORT(A2:A6, 1, FALSE)

Result:

South
South
North
North
East

One column only, Z to A. Duplicates stay.

Run in a Google Sheet (English US locale) on .

=SORT(FILTER(A2:C6, C2:C6>4), 3, TRUE)

Result:

SouthLamp5
EastBook8
NorthPen10

SORT on top of FILTER: keep rows with more than 4 units, then order them upward.

Run in a Google Sheet (English US locale) on .

=SORT(A1:D6, 3, TRUE)

Result:

NorthBook312
SouthPen42.5
SouthLamp530
EastBook812
NorthPen102.5
RegionProductUnitsPrice

The header row is inside the range here, so the text Units is sorted like data and lands at the bottom.

Run in a Google Sheet (English US locale) on .

Common errors

  • is_ascending is required, even though it looks like a small detail. =SORT(A2:D6, 3) returns #N/A. Write TRUE or FALSE.
  • sort_column counts inside range, not on the sheet. A number higher than the width of range raises no error: the rows come back in their original order, which looks like SORT did nothing.
  • If the header row is inside range, it is sorted with the data. In a number column sorted upward it ends at the bottom. Leave it outside.

Compared with Excel

Excel 365 has SORT(array, [sort_index], [sort_order], [by_col]), where the order is 1 or -1 and the column is optional. Sheets asks for TRUE or FALSE and takes extra keys as column and direction pairs.

Sources

  1. SORT (Docs Editors Help)

Markdown version · All functions