Shape · Rows

Top / Bottom N

Keeps the N rows with the largest or smallest values in one column, such as the 10 best-selling products. You choose what happens to ties at the cut-off.

Also known as: Leaderboard, nlargest

How it works

Column is the column to rank by and Number of rows the N to keep, 10 by default. Mode keeps the Largest or Smallest values. When values tie decides what happens at the cut-off: First and Last keep exactly N rows, choosing among tied rows by their input order; All ties keeps every row whose value is among the N largest (or smallest) distinct values, so tied rows never push others out and it can return more than N rows. Rows with a NULL in the column are left out. The node does not run until a column is picked.

Inputs and outputs

Inputs

  • data — Table

Outputs

  • data — Table

Settings

The Attributes panel of Top / Bottom N, as in the app: the controls work, but nothing runs — there is no data behind it.

The same settings, as the Assistant writes them
{
  column: string
  n: number
  mode: "largest"|"smallest"
  keep: "first"|"last"|"all"
}

Example

The three best-selling products, keeping every product that ties for third place: Column units, Number of rows 3, Mode Largest, When values tie All ties.

productunitskept
A120yes
B95yes
C80yes
D80yes, tied with C