List.Sort
ListSorts the items in a list according to the specified criteria.
Syntax
List.Sort(list as list, optional comparisonCriteria as any) as listParameters
| Name | Type | Required | Description |
|---|---|---|---|
list | list | Yes | The list to sort. |
comparisonCriteria | any | No | An Order value (Order.Ascending or Order.Descending) or a comparer function. |
Return Value
list — A 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 | |
|---|---|
| 1 | 120 |
| 2 | 75 |
| 3 | 50 |
| 4 | 25 |
| 5 | 15 |
Compatibility
✓ Power BI Desktop✓ Power BI Service✓ Excel Desktop✓ Excel Online✓ Dataflows✓ Fabric Notebooks