List.Sort

List

Sorts the items in a list according to the specified criteria.

Examples on this page use shared sample tables. View them to understand the input data before reading the examples below.

Syntax

List.Sort(list as list, optional comparisonCriteria as any) as list

Parameters

NameTypeRequiredDescription
listlistYesThe list to sort.
comparisonCriteriaanyNoAn Order value (Order.Ascending or Order.Descending) or a comparer function.

Return Value

listA sorted list.

Remarks

List.Sort sorts a list in ascending order by default. Pass Order.Descending for descending order, or provide a custom comparison function for advanced sorting.

Examples

Example 1: Sort prices descending

let
    Prices = List.Sort(Table.Column(Products, "Price"), Order.Descending)
in
    #table({"Price"}, List.Transform(Prices, each {_}))
Result
Price
1120
275
350
425
515

Compatibility

Power BI Desktop Power BI Service Excel Desktop Excel Online Dataflows Fabric Notebooks