KTHSMALLEST(numeric_exp, K_numeric_exp)

Returns the Kth smallest item indicated by k_numeric_exp in the population of numeric_exp.  

  

For any K supplied, there will be at most K-1 items that are smaller. If you ask for K=N (where N is the total number of things in the list), then zero elements are larger; therefore you must have the smallest item. If you ask for K=20, then up to 19 elements can be smaller.

 

For the numeric column L with values:

1,2,3,2,5,6,7,8,9,4,2,22

 

KTHSMALLEST(L, 1) /* Ask for the 1st smallest element from column L */

returns 1

 

KTHSMALLEST(L, 2) /* Ask for the 2nd smallest element from column L */

returns 2

 

KTHSMALLEST(L, 3) /* Ask for the 3rd smallest element from column L */

returns 2

 

This may seem surprising, but if you sorted the list it would look like this: 1,2,2,2,3,4,5,6,7,8,9,22 and so the 2nd, 3rd and 4th smallest elements of the list are all 2.

The result is the same as sorting the list (ascending, descending for KTHLARGEST) and then picking the Kth element from the list. But it is much faster than sorting.

 

Parameters:

numeric_exp must be a number, or a numeric expression.

k_numeric_exp must be a number, or a numeric expression.