FormulaCraft

SORT vs SORTBY: sorting by self or by another column in Excel and Sheets

Excel & Google Sheets
=SORTBY(A2:B6,B2:B6,-1)

Try it with your data

Edit the grid or formula, then run it through a real spreadsheet engine — no signup.

Sample data — click any cell to edit

Runs server-side · free · no signup

Step by step

  1. 1Place product names in A2:A6 and their sales figures in B2:B6.
  2. 2To sort the whole table by sales descending, use SORTBY: =SORTBY(A2:B6,B2:B6,-1). The first argument is the range to return; the second is the sort key; -1 means descending.
  3. 3If you only want to sort a single column by itself, SORT is equivalent and slightly simpler: =SORT(B2:B6,-1) returns just the sales column sorted.
  4. 4SORTBY accepts multiple sort-key/order pairs: =SORTBY(A2:B6,B2:B6,-1,A2:A6,1) sorts by sales descending, then by name ascending as a tiebreaker.
  5. 5To sort by a computed value not in the table (e.g. absolute deviation), use SORTBY and pass the computed array as the key: =SORTBY(A2:B6,ABS(B2:B6-AVERAGE(B2:B6)),1).

Tips

Need it for your exact data?

Describe your columns in plain English and get the precise formula for your sheet, with the right Excel or Sheets syntax.

Frequently asked

Can SORT sort by multiple columns?

Yes. =SORT(A2:C6,2,-1,3,1) sorts by column 2 descending then column 3 ascending. SORTBY achieves the same with array arguments and is often more readable.

Does SORTBY require the sort key to be the same height as the array?

Yes. The sort_by array must have the same number of rows (or columns for horizontal sorts) as the array argument, or SORTBY returns a #VALUE! error.

Will the sorted output update automatically when source data changes?

Yes. Both SORT and SORTBY are live formulas — they recalculate whenever the source range changes, so you always see the current sorted view.

Formulas used

Written and reviewed by FormulaCraft Team. Each formula on this page is run through our verification engine before publishing.

Last reviewed: