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

Table.Pivot

属性/値のペアを表す列のペアが渡されたときに、属性列のデータを列見出しにローテーションします。

Syntax

Table.Pivot(
table as table,
pivotValues as list,
attributeColumn as text,
valueColumn as text,
optional aggregationFunction as function
) as table

Remarks

属性/値のペアを表す列のペアが渡されたときに、属性列のデータを列見出しにローテーションします。

Examples

Example #1

テーブル <code>({ [ key = "x", attribute = "a", value = 1 ], [ key = "x", attribute = "c", value = 3 ], [ key = "y", attribute = "a", value = 2 ], [ key = "y", attribute = "b", value = 4 ] })</code> の属性列の値 "a"、"b"、および "c" を受け取り、それぞれの列にピボットします。

Table.Pivot(
Table.FromRecords({
[key = "x", attribute = "a", value = 1],
[key = "x", attribute = "c", value = 3],
[key = "y", attribute = "a", value = 2],
[key = "y", attribute = "b", value = 4]
}),
{"a", "b", "c"},
"attribute",
"value"
)

Result:

Table.FromRecords({
[key = "x", a = 1, b = null, c = 3],
[key = "y", a = 2, b = 4, c = null]
})

Example #2

テーブル <code>({ [ key = "x", attribute = "a", value = 1 ], [ key = "x", attribute = "c", value = 3 ], [ key = "x", attribute = "c", value = 5 ], [ key = "y", attribute = "a", value = 2 ], [ key = "y", attribute = "b", value = 4 ] })</code> の属性列の値 "a"、"b"、および "c" を受け取り、それぞれの列にピボットします。キー "x" の属性 "c" には複数の値が関連付けられるため、List.Max 関数を使用して競合を解決してください。

Table.Pivot(
Table.FromRecords({
[key = "x", attribute = "a", value = 1],
[key = "x", attribute = "c", value = 3],
[key = "x", attribute = "c", value = 5],
[key = "y", attribute = "a", value = 2],
[key = "y", attribute = "b", value = 4]
}),
{"a", "b", "c"},
"attribute",
"value",
List.Max
)

Result:

Table.FromRecords({
[key = "x", a = 1, b = null, c = 5],
[key = "y", a = 2, b = 4, c = null]
})

Category

Table.Column operations