Sort a CSV by several columns, predictably

Multi-key, stable sorting with explicit comparison types. Equal rows keep their previous order, whole records move together, and blanks go first or last as you decide.

Example data — not saved

Showing synthetic sample data: Sort a leaderboard with ties. Open or drop your own file to replace it — files are read in your browser and never uploaded.

Source AUpdating…
Loading…

Arrow keys move; Enter or double-click edits a cell (recorded as a replayable “Cell edits” step). ∅ = missing, · = edge whitespace, ↵ = line break inside a value. Row labels show source:record provenance.

How ties and blanks are handled

The example ranks a leaderboard by score (as a number, descending) and then by time. Three players share 92 points; the time key breaks the tie, and any remaining ties keep the order they had before the step.

Fi has no score. Blank and missing values are placed last regardless of direction, and values that are not valid numbers sort after the numbers so they cannot interleave unpredictably. The step reports how many such values it found.

Text order compares Unicode code points, which is the same on every device. Choose “Natural” when A2 should come before A10.

Questions

Why not sort numbers as text?

As text, 100 comes before 9. Choose “Exact number” and values are compared as exact decimals, including very large integers.

Is the sort stable?

Yes. Rows that compare equal on every key keep their relative order, so sorting twice by different keys behaves predictably.

Can I sort by a date like 31/12/2023?

Convert it to ISO format with an explicit format first; then sort as a date (or as text, which gives the same order for ISO dates).