メインコンテンツまでスキップ

Table.Sort

1 つ以上の列名と比較条件を使用してテーブルを並べ替えます。

Syntax

Table.Sort(
table as table,
comparisonCriteria as any
) as table

Remarks

1 つ以上の列名と省略可能な comparisonCriteria の一覧 (形式は { { col1, comparisonCriteria }, {col2} }) を使用して table を並べ替えます。

Examples

Example #1

テーブルを列 "OrderID" で並べ替えます。

Table.Sort(
Table.FromRecords({
[OrderID = 1, CustomerID = 1, Item = "Fishing rod", Price = 100.0],
[OrderID = 2, CustomerID = 1, Item = "1 lb. worms", Price = 5.0],
[OrderID = 3, CustomerID = 2, Item = "Fishing net", Price = 25.0],
[OrderID = 4, CustomerID = 3, Item = "Fish tazer", Price = 200.0],
[OrderID = 5, CustomerID = 3, Item = "Bandaids", Price = 2.0],
[OrderID = 6, CustomerID = 1, Item = "Tackle box", Price = 20.0],
[OrderID = 7, CustomerID = 5, Item = "Bait", Price = 3.25],
[OrderID = 8, CustomerID = 5, Item = "Fishing Rod", Price = 100.0],
[OrderID = 9, CustomerID = 6, Item = "Bait", Price = 3.25]
}),
{"OrderID"}
)

Result:

Table.FromRecords({
[OrderID = 1, CustomerID = 1, Item = "Fishing rod", Price = 100],
[OrderID = 2, CustomerID = 1, Item = "1 lb. worms", Price = 5],
[OrderID = 3, CustomerID = 2, Item = "Fishing net", Price = 25],
[OrderID = 4, CustomerID = 3, Item = "Fish tazer", Price = 200],
[OrderID = 5, CustomerID = 3, Item = "Bandaids", Price = 2],
[OrderID = 6, CustomerID = 1, Item = "Tackle box", Price = 20],
[OrderID = 7, CustomerID = 5, Item = "Bait", Price = 3.25],
[OrderID = 8, CustomerID = 5, Item = "Fishing Rod", Price = 100],
[OrderID = 9, CustomerID = 6, Item = "Bait", Price = 3.25]
})

Example #2

テーブルを列 "OrderID で降順に並べ替えます。

Table.Sort(
Table.FromRecords({
[OrderID = 1, CustomerID = 1, Item = "Fishing rod", Price = 100.0],
[OrderID = 2, CustomerID = 1, Item = "1 lb. worms", Price = 5.0],
[OrderID = 3, CustomerID = 2, Item = "Fishing net", Price = 25.0],
[OrderID = 4, CustomerID = 3, Item = "Fish tazer", Price = 200.0],
[OrderID = 5, CustomerID = 3, Item = "Bandaids", Price = 2.0],
[OrderID = 6, CustomerID = 1, Item = "Tackle box", Price = 20.0],
[OrderID = 7, CustomerID = 5, Item = "Bait", Price = 3.25],
[OrderID = 8, CustomerID = 5, Item = "Fishing Rod", Price = 100.0],
[OrderID = 9, CustomerID = 6, Item = "Bait", Price = 3.25]
}),
{"OrderID", Order.Descending}
)

Result:

Table.FromRecords({
[OrderID = 9, CustomerID = 6, Item = "Bait", Price = 3.25],
[OrderID = 8, CustomerID = 5, Item = "Fishing Rod", Price = 100],
[OrderID = 7, CustomerID = 5, Item = "Bait", Price = 3.25],
[OrderID = 6, CustomerID = 1, Item = "Tackle box", Price = 20],
[OrderID = 5, CustomerID = 3, Item = "Bandaids", Price = 2],
[OrderID = 4, CustomerID = 3, Item = "Fish tazer", Price = 200],
[OrderID = 3, CustomerID = 2, Item = "Fishing net", Price = 25],
[OrderID = 2, CustomerID = 1, Item = "1 lb. worms", Price = 5],
[OrderID = 1, CustomerID = 1, Item = "Fishing rod", Price = 100]
})

Example #3

テーブルを列 "CustomerID" で並べ替え、次に列 "OrderID" で並べ替えます。列 "CustomerID" は、昇順で並べ替えます。

Table.Sort(
Table.FromRecords({
[OrderID = 1, CustomerID = 1, Item = "Fishing rod", Price = 100.0],
[OrderID = 2, CustomerID = 1, Item = "1 lb. worms", Price = 5.0],
[OrderID = 3, CustomerID = 2, Item = "Fishing net", Price = 25.0],
[OrderID = 4, CustomerID = 3, Item = "Fish tazer", Price = 200.0],
[OrderID = 5, CustomerID = 3, Item = "Bandaids", Price = 2.0],
[OrderID = 6, CustomerID = 1, Item = "Tackle box", Price = 20.0],
[OrderID = 7, CustomerID = 5, Item = "Bait", Price = 3.25],
[OrderID = 8, CustomerID = 5, Item = "Fishing Rod", Price = 100.0],
[OrderID = 9, CustomerID = 6, Item = "Bait", Price = 3.25]
}),
{
{"CustomerID", Order.Ascending},
"OrderID"
}
)

Result:

Table.FromRecords({
[OrderID = 1, CustomerID = 1, Item = "Fishing rod", Price = 100],
[OrderID = 2, CustomerID = 1, Item = "1 lb. worms", Price = 5],
[OrderID = 6, CustomerID = 1, Item = "Tackle box", Price = 20],
[OrderID = 3, CustomerID = 2, Item = "Fishing net", Price = 25],
[OrderID = 4, CustomerID = 3, Item = "Fish tazer", Price = 200],
[OrderID = 5, CustomerID = 3, Item = "Bandaids", Price = 2],
[OrderID = 7, CustomerID = 5, Item = "Bait", Price = 3.25],
[OrderID = 8, CustomerID = 5, Item = "Fishing Rod", Price = 100],
[OrderID = 9, CustomerID = 6, Item = "Bait", Price = 3.25]
})

Category

Table.Ordering