Category: FUNCTION | Updated: 2026-11-22

How to Use the SORTN Function in Google Sheets | Extract and Sort Top N Items

What Is the SORTN Function?

The SORTN function sorts a specified data range and returns only the top (or bottom) n items. It lets you extract top-3 sales rankings or the latest entries in a single formula.

Syntax

=SORTN(range, [n], [display_ties_mode], [sort_column1, is_ascending1], ...)
  • range: The cell range to sort and extract from.
  • n (optional): The number of items to return (defaults to 1).
  • display_ties_mode (optional): A number from 0 to 3 specifying how ties are handled (defaults to 0):
    • 0: Show at most the first n rows in the sorted range
    • 1: Show at most the first n rows, plus any additional rows identical to the n-th row
    • 2: Show at most the first n rows after removing duplicate rows
    • 3: Show at most the first n unique rows, plus all duplicates of those rows
  • sort_column1 (optional): The column index (with the leftmost column of range as 1) or a single column outside range to sort by.
  • is_ascending1 (optional): TRUE for ascending order (smallest to largest), FALSE for descending order (largest to smallest).

Practical Examples

This example extracts the top 3 scorers (column 2) from test results in A2:B6, including ties.

Row Col A (Name) Col B (Score) Formula in Col D Col D (Extracted Name) Col E (Extracted Score)
1 Name Score =SORTN(A2:B6, 3, 1, 2, FALSE) Suzuki 95
2 Sato 80 (Auto-expanded) Tanaka 90
3 Suzuki 95 (Auto-expanded) Takahashi 85
4 Takahashi 85 (Auto-expanded) Watanabe 85
5 Tanaka 90
6 Watanabe 85

Note: Because display_ties_mode is set to 1, both Takahashi and Watanabe—who are tied for 3rd place (85 points)—are extracted, outputting 4 rows in total.

Common Errors and Precautions

  • #VALUE! error: Occurs if sort_column exceeds the number of columns in range, or if an external sort column does not match the height (row count) of range.
  • #REF! error: Occurs if any cell in the output expansion area already contains a value. Clear the destination area before entering the formula.
  • Do not include header rows: Including a header row (such as row 1) in range will cause the text headers to be sorted along with the data. Specify only the data rows.

Frequently Asked Questions

Q. How do I extract the 'bottom N' items instead of the 'top N' with SORTN?

A. Set the fourth argument (is_ascending) to FALSE? Wait—set it to TRUE (ascending order). Because values are sorted from smallest to largest, the bottom N items are extracted.

Q. How are ties (duplicate values) at the cutoff of N items handled?

A. You can control tie behavior with the third argument 'display_ties_mode'. Specifying 0 outputs strictly N rows, while specifying 1 outputs all tied rows as well.