Templates, guides & honest tool reviews for small business

Sunday, November 29, 2026

SORTN in Google Sheets: Top N Rows Without Sorting the Sheet

Section: Excel & Google Sheets

SORTN in Google Sheets - explanatory illustration for SORTN in Google Sheets
Illustration: SORTN in Google Sheets

SORTN in Google Sheets sorts a range and returns only the first n rows of the result. =SORTN(A2:C20,3) gives the top three rows. It is the function to reach for when you want a shortlist rather than a full sorted copy: the three best scores, the five most recent orders, the ten largest invoices. This guide covers the arguments, the four tie modes that decide how many rows you actually get, sorting by a column outside the range, and the cases where LARGE or a PivotTable is the better answer. The sample data is made up.

What SORTN does

SORTN takes a range, sorts it, and keeps n rows. Google's documentation describes it as returning the first n items in a data set after performing a sort. Because it returns an array, the result spills into the cells below and to the right, so the destination must be empty. Nothing in the source range changes.

The syntax

=SORTN(range, [n], [display_ties_mode], [sort_column1, is_ascending1], ...)

  • range is the data to sort. It can be several columns wide.
  • n is optional and defaults to 1. It is the number of rows you want back, and it must be greater than zero.
  • display_ties_mode is optional and defaults to 0. It controls what happens when rows tie.
  • sort_column1, is_ascending1 is an optional pair: which column to sort by, and whether the order is ascending (TRUE) or descending (FALSE). You can add more pairs to break ties.

If you leave the sort pair out entirely, the sort uses the lowest-index column in the range, with later columns used to break ties. That default is fine for a simple list and surprising for a wide table, so state the sort column explicitly in real work.

Arguments (made up) - explanatory illustration for SORTN in Google Sheets
Arguments (made up) (explanatory illustration, not a software screenshot).

Get the top three rows

  1. Put the data in A2:C20 with headers in row 1.
  2. Click an empty cell with room below and to the right, for example E2.
  3. Type =SORTN(A2:C20,3,0,3,FALSE) to sort by column 3, descending, and keep three rows.
  4. Press Enter. The rows spill into E2:G4.

The 0 in the third position is the tie mode, and the 3 after it is the sort column index inside the range. FALSE means descending, so the largest values come first.

The four tie modes

This is the part that decides whether you get exactly n rows or more. Google lists four values for display_ties_mode:

  • 0: show at most the first n rows of the sorted range. You get exactly n rows, and a tie at the boundary is cut arbitrarily.
  • 1: show at most n rows, plus any additional rows that are identical to the nth row. A tie at the boundary can return more than n rows.
  • 2: show at most n rows after removing duplicate rows.
  • 3: show at most n unique rows, but show every duplicate of those rows.

If a report says "top 5" and a tie at fifth place quietly gives you seven rows, mode 0 is the one to use. If you would rather show every row that genuinely shares fifth place, mode 1 is the honest choice, and the report should say so.

Top three (made up) - explanatory illustration for SORTN in Google Sheets
Top three (made up) (explanatory illustration, not a software screenshot).

Sort by a column outside the range

The sort column can be a range instead of an index, as long as it is a single column with the same number of rows as the range. =SORTN(A2:C20,5,0,D2:D20,FALSE) sorts the A:C rows by a score held in column D, which may sit outside the returned block. This is useful when the sort key is a helper column you do not want in the output. Our guide to SORT in Google Sheets covers the version that returns every row.

Sort by two columns

Add a second pair to break ties: =SORTN(A2:C20,5,0,3,FALSE,2,TRUE) sorts by column 3 descending, then by column 2 ascending. The pairs are read left to right, so the first pair is the main sort and the second only matters when the first ties. This is how you get "highest score first, then alphabetical by name".

Tie modes - explanatory illustration for SORTN in Google Sheets
Tie modes (explanatory illustration, not a software screenshot).

Common problems

  • #REF! or a blocked result. The spill area is not empty. Clear the cells below and to the right of the formula.
  • More rows than you asked for. The tie mode is 1 or 3. Use 0 for a strict count.
  • Fewer rows than you asked for. The range has fewer rows than n, or mode 2 removed duplicates.
  • The wrong column sorted. You left out the sort pair, so the first column was used. Name the column index explicitly.
  • Numbers sort as text. The column holds text that looks numeric. Convert it before sorting; formatting alone does not change the type.
  • Sorting a range outside the data. The sort column range must have the same number of rows as the data range, or the result is misaligned.

SORTN, SORT, LARGE or a PivotTable

Use SORTN for a shortlist and SORT for a full sorted copy. Use LARGE or SMALL when you need only the value, not the whole row, for example the second highest score in a column. Use a PivotTable when you need totals grouped by category, because SORTN sorts rows and does not aggregate. A filtered shortlist is a different job again, and the FILTER function handles the conditions while SORTN handles the order. If the question is "which three products sold the most in total", the data needs grouping before any sort makes sense; the QUERY function can group and sort in one formula.

Problems - explanatory illustration for SORTN in Google Sheets
Problems (explanatory illustration, not a software screenshot).

Questions and answers

Does SORTN change the source data?

No. It returns a new array. The source rows stay in their original order.

What does the n argument default to?

1, according to Google's documentation, so =SORTN(A2:C20) returns the single top row.

Can SORTN sort descending?

Yes. Set the is_ascending flag for that column to FALSE.

Does Excel have SORTN?

No. Excel has SORT, and newer builds add TAKE, which you can combine for a similar result on a version that supports both. SORTN itself is a Google Sheets function.

Why does my result spill into cells I wanted for something else?

An array result needs empty space. Move the formula, or clear the cells it needs.

Official references

العربية