How to use the SORT function in Google Sheets

The word "Sort" on a glowing green background. A Google Sheets SORT function lesson by SpreadsheetClass.com

The SORT function is an incredibly useful formula that you can use to sort your data in Google Sheets. With the SORT function you can sort your data by a specified column (or multiple columns), in ascending or descending order, and you can also sort data vertically or horizontally.

The sort function can be used to sort data alphabetically (A-Z), or numerically.

In this lesson I am going to show you how to do all of these things with the Google Sheets SORT function.

To sort by using the SORT formula in Google Sheets, follow these steps:

  1. Type "=SORT(" in a spreadsheet cell or click “Insert” → “Function” → “Filter” → “SORT”
  2. Type the range that contains the data that you want to sort, such as "A3:C"
  3. Type a comma, and then type a number which represents the column that you want to sort by, for example type the number 2 to represent the second column. Or if you want, instead of entering a column number you can type the range of the column that you want to sort by, such as "B3:B"
  4. Type a comma, and then type TRUE if you want to sort in ascending order, or type FALSE if you want to sort in descending order
  5. Press "Enter" on the keyboard. After following these steps, your sort formula will look like this =SORT(A3:C, 2, TRUE)

The formula above will sort the range A3:C, by the second column, in ascending order.

This lesson focuses on using the SORT function in Google Sheets. Click here to read the Excel version of this article

Click here to get your Google Sheets cheat sheet

Or click here to take the dashboards course

SORT formulas for Google Sheets:

Here are the types of SORT formulas that I am going to teach you in this lesson. Further below are examples of how to use each of these formulas.

Sort by a single column in ascending order

  • =SORT(A3:A)
  • =SORT(A3:A,1,true)

Sort in descending order

  • =SORT(A3:A,1,false)

Sort by range

  • =SORT(A3:B,B3:B,true)

Sort by 2 columns

  • =SORT(A3:B,2,true,1,true)

Sort by 3 columns

  • =SORT(A3:E,5,true,4,true,1,true)

Sort horizontally

  • =transpose(SORT(transpose(B1:O1),1,true))

Sort from another tab

  • =SORT(Sheet1!A3:E,3,true)

The Google Sheets SORT function:

These diagrams will show you how to set up your SORT function, and will show you what each component of the formula does, so that you can understand how to use the SORT function for custom tasks.

The SORT function works by specifying a range to be sorted, then the column number to sort by, and then the order to sort by (Ascending / Descending).

Single column Google Sheets SORT function diagram:

This diagram shows a formula that sorts a single column in ascending order.

=SORT(A3:B,2,true)

Google Sheets SORT function, a detailed formula diagram (graphic by SpreadsheetClass.com)

Multiple column Google Sheets SORT function diagram:

This diagram shows a formula that sorts by 2 columns, where the first specified column sorts in ascending order, and the second specified column sorts in descending order.

=SORT(A3:C,2,true,1,false)

A detailed diagram of sorting by 2 columns with the Google Sheets SORT function (graphic by SpreadsheetClass.com)

Setting the column number

When specifying the column to sort by in your SORT function, type a number that represents the position of the column that you want to sort by, in reference to the range that you specified.

For example, if you are sporting the range A2:C, and you want to sort by column B, then this is column "2" in the range that you are sorting by. Much the same, column C would be "3".

However if you are sorting range B2:Z, and you want to sort by column B, this would be designated as column "1", as it is the first column in the range that you specified.

The default setting for the SORT function is to sort by the first column.

Setting the sort order (Ascending vs. descending)

When specifying the order to sort by in your SORT function, choose one of the following options:

  • TRUE (Ascending)
  • FALSE (Descending)

The default setting for the SORT function is to sort in ascending order.

The Google Sheets SORT function description:

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

Formula summary: “Sorts the rows of a given array or range by the values in one or more columns.”

Sorting a single column in ascending order

First, I am going to show you how to sort a single column of data, in ascending order, with the SORT function.

When you want to sort by the first column in ascending order, you don't have to specify the column number or the TRUE / FALSE order designation. You will see that both of the formulas below do the same thing, where one has the column and order specified and the other doesn't.

In other words if you don't specify a column number and sort order, then Google Sheets will assume it is the first column in ascending order. This is perfect for sorting a basic list of names, as is shown below.

Notice that in this example the data is all text, and so the data will be sorted alphabetically.

The task: Sort the list of names in column A, from A to Z

The logic: Sort column A (A3:A) in ascending order

The formula: The formula below, is entered in the blue cell (C3), for this example

=SORT(A3:A)

Formula with same functionality: =SORT(A3:A,1,true)

An example of using the SORT function in Google Sheets. A super simple example of sorting a single column of names
A simple example of using the Google Sheets SORT function to sort a single column of names in ascending order, where the column is referenced in the formula

Sorting in descending order

In this example we will sort the same list of names in descending order (Z to A), by changing "true" to "false" in the formula.

The task: Sort the list of names in column A from Z to A

The logic: Sort column A (A3:A) in descending order

The formula: The formula below, is entered in the blue cell (C3), for this example

=SORT(A3:A,1,false)

A simple example of using the Google Sheets SORT function to sort a single column of names in descending order

Sorting by multiple columns

Now I'll show you how to use the SORT function to sort by multiple columns in Google Sheets. To do this you will specify the range to sort, then the first column that you want to sort by, then the order, and then you will do the same thing for the next column that you want to sort by.

So the first column that is specified will be the priority… and then any sorting that can be done without interrupting the grouping created by the first column designation, will be done.

In this example we will sort a list of students and their classes by class first, and then by name.

The task: Sort by class, then by student name

The logic: Sort the range A3:B, by column 2 in ascending order and then by column 1 in ascending order

The formula: The formula below, is entered in the blue cell (D3), for this example

=SORT(A3:B,2,true,1,true)

An example of how to sort by multiple columns with the Google Sheets SORT function

Sorting by numerical values

So far we have used the SORT function to sort text alphabetically, but in this example you'll see that the SORT function can also sort numerical data in Google Sheets.

(If your data has both numbers and text, numbers will sort first, and then letters after)

This first part of the example shows a list of students and their grade percentage, sorted with the lowest grades showing at the top of the list.

The task: Sort the student data by grade percentage

The logic: Sort the range A3:B, by column 2 in ascending order

The formula: The formula below, is entered in the blue cell (D3), for this example

=SORT(A3:B,2,true)

An example of sorting a range of data in Google Sheets in ascending order with the SORT function, with numerical values

Here is the same example, sorted in descending order (Best grades on top).

=SORT(A3:B,2,false)

Example of sorting a range of data in Google Sheets in descending order with the SORT function (Sorting by numerical values)

Content originally created by Corey Bustos / SpreadsheetClass.com

Sorting by a range instead of a column number

If you would like, instead of entering a column number to specify the column that you want to sort by, you can enter the range of the column that you want to sort by. For example, let's achieve the same task as the formula in the example above, but we will specify a range rather than a column number. Note that the two formulas below will do the same thing.

=SORT(A3:B,2,true)

=SORT(A3:B,B3:B,true)

The first formula refers to the second column which is column B, and the second formula refers to the range B3:B, which is again column B. Either way is an acceptable way to use the SORT function.

Note that the image below shows the same sorted results as in the example above, with the slight modification in the formula.

An example of sorting by range (instead of column number) with the SORT function in Google Sheets

Sorting by date

You can also sort data by date, by using the SORT function in Google Sheets.

Dates in a spreadsheet are really just numbers, and so earlier dates are simply just smaller numbers than later dates, making it easy to use the SORT function to sort by date.

The task: Sort the list of dates from earliest to most recent

The logic: Sort the range A2:A, by column 1 in ascending order

The formula: The formula below, is entered in the blue cell (C2), for this example

=SORT(A2:A,1,true)

An example of how to sort by date in Google Sheets with the SORT function

Sorting horizontally

You may find cases where you need to sort your data horizontally, and this can be done by using the TRANSPOSE function along with the SORT function.

The sort function expects to sort data by rows instead of columns, and this is why the TRANSPOSE function must be used if you want to sort horizontally.

The example formula below transposes the data (which switches rows and columns), then sorts the data, and then transposes it again to put the data back in the same horizontal format.

The task: Sort the list of dates horizontally, from earliest to most recent

The logic: Sort the range B1:1, by the first row in ascending order

The formula: The formula below, is entered in the blue cell (B3), for this example

=transpose(SORT(transpose(B1:O1),1,true))

An example showing how to sort horizontally in Google Sheets with the SORT function and the TRANSPOSE function

Sorting data from another tab

You may often find the need to sort data that is on another tab, where your formula output is on a tab that is separate from the tab that contains your source data.

This can be done by specifying the tab name in the data range for your SORT formula. To do this simply add the name of the tab that you want to reference as well as an exclamation point, before typing the range. For example, here we will reference the tab named "Demographics" and so our reference looks like this:

Demographics!A3:E

If your tab name has a space in it, make sure to include apostrophes before and after the tab name, like this:

'Sheet 1'!A3:Z

Let's take a look at an example of putting this into action.

The task: Sort the data on the "Demographics" tab, by city, from A to Z

The logic: Sort the range A3:E, on the tab labeled "Demographics", by the third column in ascending order

The formula: The formula below, is entered in the blue cell (A3), for this example

=SORT(Demographics!A3:E,3,true)

This is the tab named "Demographics", where the source data is located:

An example of unsorted source data on another tab, while using using the Google Sheets SORT function | SpreadsheetClass.com

This is the tab that contains the SORT formula:

An example of using the Google Sheets SORT function to sort data from another tab (Tab with formula)

Here are some more examples of sorting this same data on a single tab, in a variety of ways, so that you can see how changing the formula parameters changes the formula output.

The formulas: The formulas below, are entered in the blue cells (G3), for these examples

=SORT(A3:E,1,true)

Sorted by name in ascending order:

Example of sorting demographics data by name in ascending order. (Example of Google Sheets SORT function)

=SORT(A3:E,2,false)

Sorted by age in descending order:

Example of sorting demographics data by age in descending order (Example of Google Sheets SORT function)

=SORT(A3:E,4,true,3,true)

Sorted by state in ascending order, then by city in ascending order:

An example of sorting demographics data by 2 columns. Sort by state then by city in ascending order. (Example of Google Sheets SORT function)

=SORT(A3:E,5,true,4,true,1,true)

Sorted by gender in ascending order, then by state in ascending order, then by name in ascending order:

Example of sorting demographics data by multiple columns. Sort by gender then by state then by city in ascending order. (Example of Google Sheets SORT function)

Using the SORT function with the FILTER function

In Google Sheets, you can combine multiple functions in to a single formula.

In the video below, you will learn how to use the SORT function with the FILTER function, as individual functions, and combined into one formula. (You can also click the link to the article to learn the same thing in written format)

Using the SORT and FILTER functions together

Another very common and very useful function that you might want to learn, is the FILTER function. Check out the article linked below to learn how to use the FILTER function:

How to use the Google Sheets FILTER function

Pop Quiz: Test your knowledge

Answer the questions below about the SORT formula, to refine your knowledge! Scroll to the very bottom to find the answers to the quiz.

Classroom downloads:

Click here to get your Google Sheets cheat sheet

Or click here to take the dashboards course

Question #1

Which of the following formulas will sort by the second column, in ascending order?

  1. =SORT(A3:W, 2, false)
  2. =SORT(A3:E, 2, true)
  3. =SORT(A3:D, 1, true)

Question #2

Which of these functions will result in an error?

  1. =SORT(A3:Z,1,true)
  2. =SORT(A3:A)
  3. =SORT(A3:G,true)

Question #3

True or False: If you do not specify a column / order to sort by, the SORT function will sort by the first column in the range, in ascending order.

  1. True
  2. False

Question #4

Which of the following should be used if you want to sort in descending order?

  1. TRUE
  2. FALSE

Question #5

Which of the following formulas sorts by column 3 in ascending order, and then by column 2 in descending order?

  1. =SORT(B3:Z,2,true,1,false)
  2. =SORT(B3:Z,3,true,2,false)

Answers to the questions above:

Question 1:  2

Question 2:  3

Question 3:  1

Question 4:  2

Question 5:  2