formulastreak

Dynamic arrays function

SORT function in Google Sheets and Excel

SORT returns a range sorted by one of its columns, ascending or descending, as a list that spills and updates by itself.

Checked against Microsoft's and Google's documentation on · Example calculated on a live sheet

Syntax

SORT(array, [sort_index], [sort_order], [by_col])

Arguments in [brackets] are optional. Google Sheets writes it SORT(range, sort_column, is_ascending, [sort_column2], [is_ascending2]).

Example

=SORT(C2:C9,1,-1) reads: Sort the July sales in C2:C9 by their first (and only) column, largest first.

Q3 sales team · edit H2 and watch it recalculate
Click a cell (or use the arrow keys) to insert its address · Enter shows the resultH2 = $15,200
ABCDEFGH
1RepRegionJulAugSepTargetJul sorted
2Amara OseiNorth$12,400$13,100$11,800$36,000$15,200
3Ben FischerSouth$9,800$10,250$12,100$30,000$14,500
4Lina ChenEast$15,200$14,800$16,900$45,000$13,300
5Diego AlvarezWest$8,700$9,100$8,400$28,000$12,400
6Eva NovakNorth$11,200$12,600$13,900$36,000$11,200
7Farid HaddadSouth$13,300$12,900$14,100$39,000$10,100
8Grace KimEast$10,100$9,600$10,800$33,000$9,800
9Hugo MartinWest$14,500$15,800$15,100$42,000$8,700

H2 shows $15,200, the best July, and the list runs down to $8,700 in H9.

How the spreadsheet calculates it

Sorts C2:C9 by column 1, largest/Z first, and spills the result.

  1. 1. SORT: Sorts C2:C9 by column 1, largest/Z first, and spills the result.
    • array = `C2:C9`: what to sort
    • column = `1`: which column of it to sort by
    • order = `-1`: `1` ascending, `-1` descending (Google Sheets

More SORT examples

  • =SORT(A2:C9,3,-1)The reps with region and July sales, best July first.
  • =SORT(UNIQUE(B2:B9))Each region once, A to Z.
  • =SORT(A2:F9,{2,3},{1,-1})By region, then by July sales from high to low.
  • =TAKE(SORT(A2:C9,3,-1),3)The top three reps by July sales.

Paste any of these into the formula explainer to see it step by step.

Tips

  • Sort the whole table and choose the column with sort_index, so rows stay together.
  • Leave empty space below (or beside, with by_col) for the spill.
  • In shared files with Google Sheets users, write the direction for the app the file lives in: -1 in Excel, FALSE in Sheets.

What SORT is used for

Leaderboards and top-performer lists, sorted dropdown sources, reports that stay in order as new rows arrive, and sorted lists of unique values for summaries.

Arguments

ArgumentRequiredWhat it is
arrayYesThe range to sort, one column or several.
sort_indexNoWhich column of array to sort by: 1 is the first (the default).
sort_orderNo1 ascending (the default), -1 descending.
by_colNoFALSE (the default) sorts rows; TRUE sorts columns, for data laid out across.

Common mistakes

  • Using -1 in Google Sheets: it wants FALSE for descending.

  • Sorting one column of a table on its own: the names no longer line up with their numbers. Sort the whole table and pick the column with sort_index.

  • Typing in the cells the sorted list needs: SORT spills, and anything in the way gives #SPILL!.

In Google Sheets

Google Sheets has SORT, but its arguments are written differently: SORT(range, sort_column, is_ascending, [sort_column2], [is_ascending2]). The direction is TRUE (ascending) or FALSE (descending) instead of 1 and -1, and you can add more column and direction pairs to sort by several columns. Google's syntax line has no by_col argument.

Errors you may see with SORT

  • #SPILL!: Cells in the way of the sorted list aren't empty.
  • #NAME?: The file is open in Excel 2019 or older, which has no SORT.

Questions

How do I sort by two columns?

In Excel, give sort_index and sort_order as arrays: SORT(A2:C9,{2,3},{1,-1}) sorts by region A to Z, then July sales largest first within each region. In Google Sheets, add a second column and direction pair instead.

What's the difference between SORT and SORTBY?

SORT sorts by a column inside the range; SORTBY sorts by another range, which can be outside it or not shown at all. Google Sheets has SORT but not SORTBY.

How do I sort a list without duplicates?

Combine with UNIQUE: SORT(UNIQUE(B2:B9)) gives each region once, A to Z. See the UNIQUE and SORT guide.

Does SORT change my original data?

No. It returns a sorted copy where you type the formula; the original stays as it is, and the copy updates when the original changes.

Sources

Official documentation the facts on this page were checked against.

Practise SORT on a live sheet

Lesson 39, UNIQUE and SORT (Unit 11, Dynamic arrays), has 6 graded exercises, checked instantly, with steps and hints when you're stuck. Pro