Google Sheets: Using the SORT Function

The SORT function allows you to sort data in a range in either ascending or descending order. You can even choose to sort the data numerically, alphabetically, both horizontally and vertically. It can also add multiple sorting criteria across the columns.


The syntax is as follows:

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

where, the terms mean as follows:

  • range– this is the reference to the data range that SORT function will use.
  • sort_column– this is the reference to the column that the data will be sorted by. Note that while this column can be from outside the specified range, it can only be as long as the maximum number of rows in the specified range or it will return an error. If no value is provided the first column in the range is used by default.
  • is_ascending– this specifies the order of data output, i.e., ascending or descending. Enter TRUE for ascending and FALSE for descending. Default value is TRUE.
  • sort_column2, is_ascending2…– these parameters are used for sorting by multiple columns while the format and syntax remains exactly the same. This column will also be used to sort any ties that might occur while sorting by sort_column.

Please keep in mind that this syntax will work only when sorting columns not rows. If you want to sort by rows/horizontally, you have to use another function called TRANSPOSE with the SORT function.

Sorting data horizontally

The SORT function is designed to work with columns. Hence to make it work horizontally, we need to use the TRANSPOSE function. The TRANSPOSE function flips rows and columns into each other in an array, so by flipping the required row into a column we get something that the SORT function is able to work with.

Keep in mind to use the TRANSPOSE function twice, once for the SORT function and once to revert the data back to its original state for proper output.

Generally the function is declared as:

=TRANSPOSE(SORT(TRANSPOSE(range), sort_column, is_ascending, …))

Demonstration of TRANSPOSE function with SORT function

I hope you found this article helpful and learnt something new today.

Recent Content