Contact

SORTN Function in Google Sheets: Syntax, Examples & Troubleshooting

Lookup Intermediate Google Sheets

Return the top or bottom records with explicit sort keys and tie modes, using complete reproducible Google Sheets outputs.

Verification status: See the evidence and test scope described in this guide. How formula examples are checked

Quick answer: SORTN sorts a range and returns a limited number of rows, with options for ties and duplicate sort keys. It combines ordering and selection without rearranging the source cells.

Availability and version history

  • Introduced: Original introduction date is not established by the official history reviewed.
  • Availability: Documented in the rolling Google Sheets service. This guide covers ordinary worksheet formulas in the web workflow; it does not establish separate mobile or connected-database behavior.
  • Checked: October 14, 2026, against the official SORTN reference. Documentation and independent calculations; no native application execution.

Syntax and defaults

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

n defaults to 1 and must be positive. Tie mode defaults to 0. Use TRUE for ascending or FALSE for descending order. A sort key may be a column index within the source or an aligned one-column external range. Additional key/direction pairs break ties in priority order.

Without explicit keys, Google describes sorting from the leftmost column, using later columns to resolve ties. Write the keys and directions explicitly when the ranking is important.

Tie modes are 0: at most n rows; 1: include ties at the cutoff; 2: retain up to n distinct sorted entries; 3: include duplicates of the first n distinct entries. Google’s worked examples demonstrate that specified sort keys affect tie identity. Do not assume different names prevent a tie when sorting only by a score.

Prepare an order table

Enter the following in A1:C7. The table shown has exactly three worksheet columns.

Item Amount Ticket
Cedar 90 104
Birch 75 102
Maple 90 101
Elm 60 105
Pine 75 103
Ash 50 106

Amounts are numeric. Ticket values are unique tie-breakers, not measures of quality. Put outputs outside A1:C7.

Example 1: highest three with a deterministic tie-breaker

=SORTN(A2:C7,3,0,2,FALSE,3,TRUE)

The complete result is:

Item Amount Ticket
Maple 90 101
Cedar 90 104
Birch 75 102

These headings explain the output; the formula returns only three data rows. Amount is descending, then Ticket is ascending. Pine also has 75, but mode 0 stops after three rows and its ticket follows Birch’s.

Example 2: lowest two

=SORTN(A2:C7,2,0,2,TRUE,3,TRUE)

The expected rows are Ash,50,106 and Elm,60,105. Changing the amount direction reverses the ranking criterion, not the source data. No manual sorting is needed before entering the formula.

Advanced example: compare all four tie modes on one column

On a separate sheet enter 90, 75, 90, 60, 75, 50 in A2:A7. Use each formula in a different clear column:

=SORTN(A2:A7,3,0,1,FALSE)
=SORTN(A2:A7,3,1,1,FALSE)
=SORTN(A2:A7,3,2,1,FALSE)
=SORTN(A2:A7,3,3,1,FALSE)

The expected vertical outputs are:

  • Mode 0: 90, 90, 75
  • Mode 1: 90, 90, 75, 75
  • Mode 2: 90, 75, 60
  • Mode 3: 90, 90, 75, 75, 60

The cutoff in mode 1 lies in the 75 group, so both 75 values appear. Mode 2 counts distinct values after removing repeats. Mode 3 selects the first three distinct values and retains all their occurrences. This one-column case makes tie identity unambiguous.

Advanced example: a complete tied-score group

Return to the original three-column table:

=SORTN(A2:C7,3,1,2,FALSE)

Both 90 records and both 75 records qualify, producing four rows. The selected records are Cedar, Maple, Birch and Pine, with their original amounts and tickets. This example intentionally does not assert the within-tie row order because no second key is supplied.

Adding Ticket as a second sort key distinguishes those previously tied records. Do not add a unique tie-breaker and still expect mode 1 to expand every amount-only tie. Choose whether the business question concerns complete score groups or a fixed ordered list.

Errors and verification

Keep external key ranges the same height as the source and exclude headings unless they are meant to be sorted as data. A positive n is required; this guide does not assign native error codes to every invalid argument combination. Leave enough space for tie modes that can exceed n rows.

All complete ordered outputs and tie membership above were independently calculated, not executed in Sheets. Use comma separators for the stated locale. For unbounded sorting use SORT; for conditions use FILTER; for distinct records without top-n ranking see UNIQUE.

Official reference and testing scope