How to Use the SORTN Function in Google Sheets

By Tomosuke Hasegawa · Updated Oct 29, 2026 · Advanced · 6 min read · includes 2 free exercises

In short: SORTN sorts a range and returns the first n rows. The formula is =SORTN(range, [n], [display_ties_mode], [sort_column1, is_ascending1], ...).

What SORTN does

A leaderboard needs the top three, not the whole list. SORT returns everything in order, and you would then have to cut it down. SORTN does both in one step: it sorts and returns only the first n rows.

SORTN syntax

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

Per the help page, only the specified sort columns determine order. If you give no sort column, the sort uses the lowest-index column, and later columns break ties.

A step-by-step example

Here are five scores in cells A1:B6.

AB
1NameScore
2Ann82
3Ben54
4Cara67
5Dev91
6Eli73
=SORTN(A2:B6, 2, 0, 2, FALSE)

This returns two rows: Dev with 91 and Ann with 82. Here is why: the data is sorted by column 2, the score, in descending order, and only the first 2 rows are kept. Display mode 0 means no extra tied rows are added. To get the lowest score instead, sort ascending and keep one row:

=SORTN(A2:B6, 1, 0, 2, TRUE)

This returns Ben with 54.

Common mistakes

Try it yourself

Use the table above (A1:B6). Type your formula into the box, starting with =, then press Check.

Exercise 1: Top two scores

Write a formula that returns the top 2 rows of A2:B6 by score (column 2), highest first, with no extra tied rows.

Hint: n is 2, display mode 0, order FALSE.

Exercise 2: Lowest score

Write a formula that returns the single row with the lowest score in A2:B6.

Hint: n is 1 and the order is ascending.

What to learn next

Syntax and rules in this guide were checked against Google's SORTN help page. See all guides.