# Sort

> Put a list in order by one of its fields, smallest first or largest first.

The **Sort** step puts a list in order. You name the field to sort by and the direction, and it returns the same items rearranged.

> Dock: Data · Lists · Takes: a list · Returns: the same list, reordered

Use it when order carries meaning: the highest-value orders first, the oldest tickets first, names in alphabetical order for a report someone will read.

> **Sorting inside a field?** You can sort or reverse lists directly inside field tokens using [Data Transformation](/build/core-concepts/data-transformation):
> - Sort alphabetically or by field: `{{ 2.records | sort:ascending:name }}`
> - Reverse ordering: `{{ 2.records | reverse }}`
>
> Use the **Sort** canvas step when you need multi-level tie-breaking rules (e.g. priority then date) or when dealing with large datasets (up to 100,000 items).

## Setting it up

### Choose the list

Pick it from the lists the field offers, which come from the steps before this one. Choose **Enter it myself** to type a reference such as `{{ 3.results }}` or paste a JSON list instead.

### Add a **Sort by** row

Name the field inside each item, such as `total` or `created_at`. Leave the field blank to compare each whole item, which suits a list of plain values.

### Choose the direction

Ascending puts the smallest first, descending the largest. **Type** starts as **Automatic**: Sort reads the values and works out whether they are text, numbers or dates. Pick **Text**, **Number** or **Date** yourself only when you want to override that.

### Add more rows if one is not enough

Up to ten, applied in the order they are listed. The second row only decides ties in the first.

## Breaking ties with a second rule

One rule sorts by one thing, and leaves entries that share that value in whatever order they arrived.

**Add a second row to decide those.** Sort support tickets by priority, then by date. The urgent ones come first, oldest of them at the top:

| Row | Field        | Type | Direction |
| --- | ------------ | ---- | --------- |
| 1   | `priority`   | Text | Ascending |
| 2   | `created_at` | Date | Ascending |

Rows are applied in order, so the first one is the one that matters most.

## Automatic works the type out for you

Text, numbers and dates sort differently, and the same list comes back in a different order depending on which one Sort uses.

Sorted as text, `100` comes before `20`, because text is compared character by character and `1` comes before `2`. Sorted as numbers, `20` comes first.

**Type** starts as **Automatic**: Sort reads every value in the column and picks the one type they all share. When the list has run data, the panel shows what it decided, such as _Automatic - Number_. If the values disagree, say dates mixed with plain text, the run stops and names the two items that conflict. Choose **Text**, **Number** or **Date** yourself and the run continues with your answer.

An explicit type is also how you override the guess, for example numeric product codes that should sort as text. **If the type you choose does not match what is in the list, Sort refuses rather than guessing.** It names the item it could not read, so you can open that entry and see what it holds.

## Capital letters affect text ordering

Sorting text is exact by default, and capitals sort before lower case, so `Zebra` comes before `apple`.

**Ignore capitalisation** turns that off, and the list orders the way a person would expect. Leave it off when case carries meaning, as it does in product codes.

## What it passes on

The same items in the new order:

```
{{ 5.$full_result }}
```

Nothing is added or removed. A list of ten comes back as a list of ten.

The step also counts the items for you: `{{ 5.resultCount }}` is how many it passed on, and `{{ 5.results }}` is the list as the data panel offers it.

## Examples to copy

### Highest value first

Orders from a shop, largest first, so a report can lead with them.

- **Field**: `total`
- **Type**: Number
- **Direction**: Descending

Follow it with a [Limit](/build/action-steps/limit) to keep only the top few.

### Oldest ticket first

A support queue, so the longest-waiting request is dealt with first.

- **Field**: `created_at`
- **Type**: Date
- **Direction**: Ascending

Automatic picks both of these types up on its own. Set the type explicitly when you want to pin it.

## Limits

Sort works on lists of up to 100,000 items and takes at most ten **Sort by** rows. Beyond either, it refuses and says so rather than returning a partial answer. Split the list first, or drop the least important rule.

## What's Next?

- 👉 **[Limit →](/build/action-steps/limit)**: take the first few items after sorting them.
- **[Filter](/build/action-steps/filter-items)**: remove entries before sorting the list.
- **[Summarize](/build/action-steps/summarize)**: count or total a list instead of reordering it.
