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.
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).
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.
Imagine you are analyzing sales data for a company and you want to find the top-selling products based on their sales figures.
| ProductID | ProductName | Sales |
|---|---|---|
| 101 | Widget A | 250 |
| 102 | Widget B | 300 |
| 103 | Widget C | 150 |
| 104 | Widget D | 400 |
| 105 | Widget E | 200 |
You want to extract the top 3 products based on sales.
To achieve this, you would use the SORTN function as follows:
=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).When you apply the SORTN formula to the Sales Data Table, the output would look like this:
| ProductID | ProductName | Sales |
|---|---|---|
| 104 | Widget D | 400 |
| 102 | Widget B | 300 |
| 101 | Widget A | 250 |
This result shows the top 3 products based on sales figures.
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.
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!
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.
Sign up for Better Analyst and get unlimited AI-powered formula generation, explanations, and advanced data analysis.
Browse our complete library of Google Sheets formula guides
Compare your options
Open a neutral research prompt in the AI tool you already use. Compare capabilities, limitations, and fit before you choose.
AI answers can be incomplete. Check source links, current pricing, and product documentation before deciding.