Returns the first n items in a data set after performing a sort. Learn more
SORTN is a function in Google Sheets that allows you to sort a range of data based on specified criteria and return the top "n" results. The function syntax is as follows:
SORTN(range, [n], [displaytiesmode], [sortcolumn1, isascending1], [sortcolumn2, isascending2], …)
range: This is the data range that you want to sort. n (optional): This is the number of top results that you want to return. If omitted, all results will be returned. displaytiesmode (optional): This specifies how to handle ties when multiple rows have the same values in the sort columns. The default mode is "SKIP", which skips tied values and returns the next unique value. Other modes include "SHOW", which displays all tied values, and "CUSTOM", which allows you to specify a custom function to handle ties. sortcolumn1, isascending1 (required): These are the first sort column and sort order. You can specify up to 15 sort columns and their corresponding sort orders. For example, if you have a table of sales data with columns for product name, sales amount, and region, you can use the SORTN function to find the top 3 sales by region:
=SORTN(A2:C10, 3, , 3, FALSE, 2, FALSE)
This function sorts the range A2:C10 by region in descending order (FALSE), then by sales amount in descending order (FALSE), and returns the top 3 results. If there are ties in the top 3 results, the default "SKIP" mode will be used to skip tied values and return the next unique value.