SORTN
The SORTN function in Google Sheets returns the first n items in a data set after performing a sort. It is a useful tool for filtering and organizing data based on specific criteria.
Function Syntax and Parameters
Syntax: SORTN(range, [n], [display_ties_mode], [sort_column1, is_ascending1], [...])
Parameters:
- range: The range of cells or a data array to be sorted.
- n: [Optional] The number of items to return. If omitted,- nwill default to 1.
- display_ties_mode: [Optional] Specifies how ties are handled when two or more items have the same sort values. Possible values are "ALL", "DISPLAY_FIRST", "DISPLAY_LAST", and "CUSTOM".
- sort_column1, is_ascending1: [Optional] Specifies the first sort column and its sorting order. Additional sort columns can be added as parameters.
Step-by-Step Tutorial
- 
Basic usage of SORTN:- Example: =SORTN(A1:B5, 3)
- Result: Returns the first 3 items from the range A1 to B5after sorting them.
 
- Example: 
- 
Sorting with multiple columns and custom tie-breaking rules: - Example: =SORTN(A1:B5, 2, "CUSTOM", 1, TRUE, 2, FALSE)
- Result: Sorts the range A1 to B5based on the values insort_column1(ascending order) andsort_column2(descending order) while customizing how ties are displayed.
 
- Example: 
Use Cases and Scenarios
- Top N Sales: Retrieve the top N items from a sales dataset based on the highest sales figures.
- Ranking Players: Determine the highest-scoring players in a sports tournament.
- Budget Analysis: Find the top N expenses or income sources in a budget sheet.
Related Functions
- SORT: Sort a range of cells or a data array.
- LARGE: Get the nth largest value from a range.
- SMALL: Get the nth smallest value from a range.