Sort Function

=Sort Function

The SORT function sorts the contents of a range or array.

In this example we are sorting an array of sales which currently unordered. When =SORT(B3:E51) is used we will see the array now sorted by the first column, in this case A-Z of the Item column:  Illustrative image





The range or array from which to return unique rows or columns

[sort_index] (optional) A number, indicating the row or column to sort by. Unless specified otherwise, the first column will be the default 
[sort_order] (optional)A number indicating the sort order, 1 for ascending order (default) and -1 for descending order 
[by_col] (optional)Sort direction (Row or columns) 'False' to sort by row, True to sort by column 


You can also use =Sort nested within other functions such as:

Further examples:

  1. =SORT(B3:E51,2,1) 
    In this example the sort_index is 2. This means the array will sorted by the 'salesperson' column as it's the second column. Also the sort_order is 1, so the sort will be ascending from A-Z:  Illustrative image
  2. =SORT(B3:E51,3,-1,FALSE)
    In this example the sort_index is 3, meaning the array will be sorted by the 'amount' column. Also the sort_order is -1, so the sort will be descending from highest to lowest. We are also specifying FALSE to make sure we are sorting by rows and not columns:  Illustrative image
  3. =SORT(FILTER(B3:E51,B3:B51=G3),2,1)
    It's possible to combine the sort function with other functions, in this case 'filter'. This will sort the filtered data, by whatever sort_index you select, in this case 2, which is the 'salesperson' column.  This function has filtered by 'laptop' found in G3.  Illustrative image
    If you are unfamiliar with the filter function you can find a guide here


Still need help?