Ordering
Learn how to order data.
A collection can be ordered using Collection.OrderBy
.
A list can be ordered using List.OrderBy
.
In the example, a dataset is read and filtered. The resulting collection
is then ordered: first by column Quantity
in descending order, then by column
NetAmount
in ascending order. The ordering on NetAmount
applies when two
rows have the same value as Quantity
:
let table = Csv.InferAndRead("https://raw-tutorial.s3.eu-west-1.amazonaws.com/Lokad_Orders.csv"),
subset = Collection.Filter(table, d -> d.Date == day)
in Collection.OrderBy(subset, row -> row.Quantity, "DESC", row -> row.NetAmount, "ASC")
info
If you want to try this example, you can deploy the following endpoint:
Ordering rows
Learn how to sort elements in a collection.
- Overview
- Code
Sample usage:
/orders?day=<date>
For instance:
/orders?day=2017-12-04
main(day: date) =
let
table = Csv.InferAndRead("https://raw-tutorial.s3.eu-west-1.amazonaws.com/Lokad_Orders.csv"),
subset = Collection.Filter(table, (d) -> d.Date == day)
in
Collection.OrderBy(subset, (row) -> row.Quantity, "DESC", (row) -> row.NetAmount, "ASC")
// The following test will run if you press the [Run Code] button directly.
main(Date.Build(2017, 12, 4))