How to Use the SORT Function in Google Sheets

How to Use the SORT Function in Google Sheets

In this tutorial, I am going to show you how to use the SORT Function in Google Sheets.

The ability of Google Sheets to record and store data is probably the best of all its powerful functionalities. That said, you can only get so far with data that needs to be properly sorted.

That is why in the many years I’ve used Google Sheets, I’ve always tried to organize my data in the most meaningful way possible. The SORT Function in Google Sheets helped me achieve that goal.

How to Use the SORT Function in Google Sheets

  1. Define the range to be sorted
  2. Identify the sort_column within that range
  3. Declare whether the sorting by is_ascening is TRUE or FALSE
  4. Use the formula =SORT(range, sort_column, is_ascending)
  5. Hit ENTER or click on another cell to finish
How to Use the SORT Function in Google Sheets
How to Use the SORT Function in Google Sheets

Sorting in Google Sheets Video Tutorial

4 Ways to Use the SORT Function in Google Sheets

SORT arranges the cells or rows of a declared array or range by the values in one or more columns.

The syntax of the SORT Function in Google Sheets is

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

Where:

  • range: is the array or range to be sorted
  • sort_column: is the column that will be used as a reference for the sorting of the whole selected range
  • is_ascending: can either be TRUE or FALSE where the former is for ascending and the latter is for descending

To show you how the SORT Function in Google Sheets works, I created some examples below.

1. Sort a Defined Range

This way shows how the SORT Function in Google Sheets works wherein it takes a range, a reference column in that range for sorting, and an identifier for the direction of the sorting whether it’ll go in an ascending or descending manner.

To start, we need a range as seen below. This is created through an array.

An array showing a dataset of numbers and colors on two columns and six rows
An array showing a dataset of numbers and colors on two columns and six rows

I took this array and used it as the range parameter of SORT. Additionally, I want the numbers-column to be used as the sort_column parameter in sorting in a descending manner.

An array is used as the range parameter of SORT in a descending sorting
An array is used as the range parameter of SORT in a descending sorting

In the next example, I used the colors-column as the sort_column parameter in sorting in an ascending manner.

An array is used as the range parameter of SORT in an ascending sorting
An array is used as the range parameter of SORT in an ascending sorting

If you want to keep a record of the original sorting of your data, it’s best ot make a copy of it at this point. Alternatively, you can also create an index column that will act as an index so you can unsort your dataset if needed.

2. Sort a Single Column Range

A more practical way of using the SORT Function in Google Sheets is to use it with a range existing in different column or columns.

In doing so, I just need to reference the range as the 1st parameter of SORT as seen in the first example below.

Using SORT on a single column ascendingly
Using SORT on a single column ascendingly

Other than naming the order of the sort_column in the range that has been selected (in this example: “1”), I can also use the range of the column as the 2nd parameter of sort as seen below.

This is most useful when using a range with a lot of columns where it’ll be a chore to count from the start. Instead of using the sort_column’s order in that range, I can just use its cell reference.

Using SORT on a single column ascendingly with a range as its second parameter
Using SORT on a single column ascendingly with a range as its second parameter

In the next example, I’ve set SORT to be descending where the formula has FALSE as its 3rd parameter.

Using SORT on a single column descendingly
Using SORT on a single column descendingly

This is the most basic use of the SORT Function in Google Sheets. That said, using SORT on a range with multiple columns can be more useful.

3. Sort a Range with Multiple Columns

When using the SORT Function in Google Sheets on multiple columns instead of a single column, every column is sorted at the same time dependent on how the sort_column will be set as ascending or descending.

Below is an unsorted dataset of names and birthdays. I’ve created a custom column at the right-most end showing each person’s range depending on the DOB. As you can see, they are yet to be sorted in any manner.

A sample dataset that is currently unsorted
A sample dataset that is currently unsorted

I want to see this table sorted to show the youngest person to the oldest. To do so, I need to set the third parameter of SORT to FALSE or descending. This causes the dates to have the most recent one at the top and the oldest one at the bottom.

The sample dataset sorted descendingly by its Date of Birth column
The sample dataset sorted descendingly by its Date of Birth column

Alternatively, I can also sort the table to show the oldest person first. To do this, I need to change the third parameter of SORT to TRUE or ascending. Where the oldest dates are at the top with the most recent ones at the bottom.

The sample dataset sorted ascendingly by its Date of Birth column
The sample dataset sorted ascendingly by its Date of Birth column

There are many ways to sort by date; this is one of the most useful.

4. Sort a Horizontal Range

The SORT Function in Google Sheets only works on columns. That said, it won’t work if you want to sort rows if no changes were made to them.

To circumvent this, I have to use the TRANSPOSE Function. Where if a row is used as its range, it will be shifted to a column and vice-versa.

The syntax of TRANSPOSE is

=TRANSPOSE(array_or_range)

Where its sole parameter is any column or row.

Now, to sort a horizontal range with the SORT Function in Google Sheets, we can use this syntax

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

As seen below where the horizontal table was sorted by its ‘Product Name’ row.

A dataset with 2 rows sorted by using TRANSPOSE with SORT
A dataset with 2 rows sorted by using TRANSPOSE with SORT

This works by TRANSPOSE converting the rows into columns and then was sorted and then was transposed back to rows showing the sorted result.

Frequently Asked Questions about How to Use the SORT Function in Google Sheets

How can I sort columns with the SORT Function in Google Sheets?

Sort columns with the SORT Function in Google Sheets by defining the range and sort_column. Next, declare whether the sorting by is_ascening is TRUE or FALSE and use the formula =SORT(range, sort_column, is_ascending). Lastly, hit ENTER or click on another cell to finish.

How can I sort rows with the SORT Function in Google Sheets?

Sort columns with the SORT Function in Google Sheets by defining the range and sort_column. Next, declare whether the sorting by is_ascening is TRUE or FALSE and use the formula =TRANSPOSE(SORT(TRANSPOSE(range),sort_column,is_ascending)). Lastly, hit ENTER or click on another cell to finish.

Conclusion on How to Use the SORT Function in Google Sheets

You can use the SORT Function in Google Sheets by defining the range to be sorted and then identifying the sort_column within that range. Next, declare whether the sorting by is_ascening is TRUE or FALSE and use the formula =SORT(range, sort_column, is_ascending). Lastly, hit ENTER or click on another cell to finish.