SORT Function in Google Sheets

The SORT function lets you sort a range of data in Google Sheets. It is similar to the sort options found in the menus but leaves the source data unsorted.

Help text for the SORT function

The function creates a new dynamic range of data with the sorted output from the function.

The SORT Formula Creating a Dynamic Array

💡If you find yourself nesting functions from the filter family (FILTER, SORT, SORTN, UNIQUE), consider using the QUERY function instead. QUERY is more powerful and easier to use than nested filter functions.

Video Explanation

Purpose

Returns sorted data from your specified source.

Syntax

=SORT(range,sort_column,is_ascending,[sort_column2, is_acending2,...])

  • range – The data to be sorted
  • sort_column – The column containing the criteria you are sorting.
  • is_ascending – Two possible answers – TRUE for ascending (1,2,3), FALSE for descending (3,2,1)

Related Functions

FILTER â€“ Outputs a filtered range of data

SORTN â€“ Sorts a range of data and returns the first n items

UNIQUE â€“ Outputs data with duplicates removed

QUERY â€“ A flexible function that can filter output

Examples

Example 1 – A Simple Ascending Sort

This first example uses a simple SORT function with one column of data sorted in ascending order.

A simple, ascending sort
A Simple Ascending Sort

Function used: =SORT(B1:B3,1,TRUE)

The formula in cell B5 points to the range of B1:B3 for the unsorted data. The sort_column is 1, which is column B. A TRUE for is_ascending input tells the function to rearrange the data from smallest to largest, which is why the output is 2, 3, 5.

Example 2 – A Two-Columns Range

Let’s look at an example now of sorting a table with two columns of data and sorting in descending order with the second column as the value to sort by.

The SORT function handling two columns of data
Two Columns Sorted Descending

Formula used: =SORT(B1:C3,2,FALSE)

The first three rows are the original data, and the last three are the function’s dynamic results. The function is still in cell B5, and you can see it if you select that cell. Since Google Sheets used the second column, Google Sheets sorted those values in backward alphabetical order – b, r, t.

💡 This function’s output can spill below, and sometimes to the right, of its cell.

Example 3 – Sorting by Two Columns

Lastly, we have two columns sorted by column 2 in ascending order and then by column 1 in ascending order.

Two columns of data sorted with both columns
Two Columns Sorted by Both Columns

Formula used: =SORT(B1:C6,2,TRUE,1,TRUE)

Notice that the data is now sorted by the last name, but also Dewey comes before Huey and Louie.

Live Examples in Sheets

Go to this spreadsheet for several examples of the SORT function that you can study and use anywhere you want.

Leave a Comment