Google Sheets SORTN Function: Syntax, Examples & Tips

The SORTN function returns a specified number of rows from a sorted range, allowing for filtering and deduplication of data.
Google Sheets
SORTN(range, [n], [display_ties_mode], [sort_column1, is_ascending1], ...)

One free generation or explanation per browser, shared across Excel and Google Sheets. Account usage limits apply afterward.

On this page
  1. Parameters
  2. What is a SORTN?
  3. A Practical Example
  4. SORTN Formula
  5. Result of the Formula
  6. Why Use SORTN?
  7. Key Takeaways:
  8. Example use case

Parameters

range:
The range of cells that you want to sort and evaluate.

n:
The number of items to return from the sorted range. If omitted, all items are returned.

display_ties_mode:
An optional parameter that determines how to handle ties in the sorting. It can be set to 0 (default, display all), 1 (display only the first n items), 2 (display the first n unique items), or 3 (display all items with the same value as the nth item).

sort_column1:
The column index (1-based) to sort by. This is required if you want to sort the range.

is_ascending1:
A boolean value (TRUE or FALSE) that specifies whether to sort the first sort column in ascending order (TRUE) or descending order (FALSE).

What is a SORTN?

The SORTN function in Google Sheets is a powerful tool used to sort a range of data and return a specified number of rows from that sorted data. It is particularly useful for extracting the top or bottom N entries based on specific criteria, making it a great choice for data analysis and reporting. SORTN can handle duplicates and allows for various sorting options, providing flexibility in how you present your data.

In simpler terms, SORTN allows you to organize your data in a meaningful way and focus on the most relevant entries.

A Practical Example

Imagine you are analyzing sales data for a company and you want to find the top-selling products based on their sales figures.

Sales Data Table:

ProductIDProductNameSales
101Widget A250
102Widget B300
103Widget C150
104Widget D400
105Widget E200

You want to extract the top 3 products based on sales.

SORTN Formula

To achieve this, you would use the SORTN function as follows:

Google Sheets
=SORTN(A2:C6, 3, FALSE, 3)

In this formula:

  • A2:C6 is the range containing your sales data.
  • 3 specifies that you want to return the top 3 entries.
  • FALSE indicates that you want to sort in descending order (highest sales first).
  • 3 specifies that the sorting should be based on the third column (Sales).

Result of the Formula

When you apply the SORTN formula to the Sales Data Table, the output would look like this:

ProductIDProductNameSales
104Widget D400
102Widget B300
101Widget A250

This result shows the top 3 products based on sales figures.

Why Use SORTN?

SORTN is beneficial because it simplifies the process of sorting and filtering data in Google Sheets. It allows you to quickly identify key entries without the need for complex formulas or manual sorting. Additionally, it can handle duplicates and provides options for sorting in both ascending and descending order, making it a versatile tool for data analysis.

Key Takeaways:

  • SORTN: A modern Google Sheets function that sorts data and returns a specified number of rows.
  • Versatile: Can handle duplicates and allows for sorting in both ascending and descending order.
  • Efficiency: Simplifies the process of identifying top or bottom entries in your data set.
  • Common Use Cases: Ideal for sales analysis, performance tracking, and any scenario where you need to focus on key data points.

SORTN is an essential function for anyone working with data in Google Sheets, providing a powerful way to enhance data analysis and reporting capabilities.

Happy spreadsheeting!

Example use case

You have a list of sales transactions in a table with columns for product names and sales amounts. Use the SORTN formula to quickly display the top 5 products by sales, allowing for easy identification of best-selling items for inventory decisions.

Need more help with Google Sheets formulas?

Sign up for Better Analyst and get unlimited AI-powered formula generation, explanations, and advanced data analysis.

Explore all Google Sheets formulas

Browse our complete library of Google Sheets formula guides

Compare your options

Decide with evidence, not a sales pitch.

Open a neutral research prompt in the AI tool you already use. Compare capabilities, limitations, and fit before you choose.

  1. 01ChatGPTOpen a balanced comparison prompt in ChatGPT.
  2. 02ClaudeOpen the same research prompt in Claude.
  3. 03PerplexityResearch the comparison with linked web sources.

AI answers can be incomplete. Check source links, current pricing, and product documentation before deciding.