SORTN
the first n rows of a range after sorting · from google sheets · no excel equivalent · sheets: not yet compared
signature
SORTN(range, [n], [display_ties_mode], [sort_column], [is_ascending])
returns: array
| argument | required |
|---|---|
| range | required |
| n | optional · defaults to 1 |
| display_ties_mode | optional |
| sort_column | optional · defaults to 1 |
| is_ascending | optional · defaults to 1 |
examples
formula and result, taken from the engine's own test suite — every result below is asserted in CI, not written by hand.
| A | |
|---|---|
| 1 | 10 |
| 2 | 20 |
| 3 | 30 |
| 4 | 40 |
| 5 | 50 |
fx
=SORTN(A1:A5, 2) 10 related
- ARRAY_CONSTRAIN truncates a range to at most the given rows and columns
- ARRAYFORMULA evaluates an expression across a range (this engine already spills, so it is a pass-through for sheets compatibility)
- ARRAYTOTEXT converts array to text representation
- BYCOL applies lambda to each column of array
- BYROW applies lambda to each row of array
- CHOOSECOLS returns the specified columns from an array