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:
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:
- - =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:
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:
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.
If you are unfamiliar with the filter function you can find a guide here