Skip to main content

CSV sorting guide

How to sort a CSV by text or numeric columns

Sort by State ascending, Amount descending, or up to three prioritized keys. Rows equal on every selected key retain their original order.

Published:

Updated:

Related tool: Sort rows

Example: highest sales within each state

Sort State as ascending text and Amount USD as descending numbers, with blanks last.

  • Key 1: State, text, ascending
  • Key 2: Amount USD, number, descending
  • Blank values: last

Unsorted sales

States and amounts are mixed in the input.

state_sales.csv
Invoice,State,Amount USD
V001,Texas,840.00
V002,California,1280.00
V003,Texas,2150.00
V004,California,990.00

Sort by multiple columns

Make State the first key and Amount USD the second. The second comparison runs only within a state. Putting Amount first would make V003 from Texas the first invoice overall.

  1. Open Sort rows and choose the CSV.
  2. Configure column, type, direction, and blank placement for key 1.
  3. Add and reorder up to two more keys when needed.
  4. Confirm case sensitivity and run the sort.
  5. Verify counts and check the first and last rows, then download.
Sort rows

State ascending, amount descending

Check where California ends and Texas begins. California’s 1280 comes before its 990, then Texas starts over at 2150. If the 2150 row is first in the file, move State above Amount USD.

state_sales_sorted.csv
Invoice,State,Amount USD
V002,California,1280.00
V004,California,990.00
V003,Texas,2150.00
V001,Texas,840.00

Common sorting mistakes

Text and number modes produce intentionally different orderings.

  • Sorting money as text
  • Selecting Number for values with commas or currency signs
  • Sorting mixed date formats as plain text
  • Assuming ascending or descending decides blank placement

Where this sort fits

It is useful for presentation order and as a preparation step before deduplication.

  • Good fit: up to three text or numeric keys
  • Good fit: preserve the order of ties
  • Date-aware sorting and language-specific alphabetical order are unsupported
  • Use Group and summarize to create summaries