Downloads
Power Query MList: transform and filterBeginner

List.Sort

Returns the items of a list in order, smallest to largest by default.

Syntax
List.Sort(list, optional comparisonCriteria)

Returns: A new sorted list. The original list is not changed.

What it does

List.Sort puts the items in order. By default that is ascending (smallest first for numbers, A to Z for text, earliest first for dates). Pass Order.Descending to reverse it. Use it when you need the values in a fixed order, for example to list the largest expenses first or to show months in calendar order.

Syntax and arguments

Example

A cost controller wants the expense categories for the quarter listed from largest to smallest, starting from a list of amounts.

let
    Amounts = {4200, 310, 18750, 980},
    Largest = List.Sort(Amounts, Order.Descending)
in
    Largest

The result is {18750, 4200, 980, 310}. Sorting a list of plain numbers is simple. To sort a table by a column, use Table.Sort, which keeps each row's other columns together.

Example: a second, different use

Sorting text: List.Sort({"West", "East", "North"}) gives East, North, West.

Things to watch

In business terms

Top-ten expense lists, aging buckets in order, months in calendar order and rankings of customers by balance all depend on sorting. Sort the data before a report so the order is not left to chance.

Related functions

All Power Query M functions · View as Markdown · M basics