Lewati ke konten utama

Table.Pivot

Dengan sepasang kolom yang mewakili pasangan atribut-nilai, memutar posisi data di kolom atribut ke heading kolom.

Syntax

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

Remarks

Dengan sepasang kolom yang mewakili pasangan atribut-nilai, memutar posisi data di kolom atribut ke heading kolom.

Examples

Example #1

Mengambil nilai "a", "b", dan "c" di kolom atribut tabel ({ [ key = "x", attribute = "a", value = 1 ], [ key = "x", attribute = "c", value = 3 ], [ key = "y", attribute = "a", value = 2 ], [ key = "y", attribute = "b", value = 4 ] }) dan mempivot ke kolomnya masing-masing.

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

Mengambil nilai "a", "b", dan "c" di kolom atribut tabel ({ [ 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 ] }) dan mempivot ke kolomnya masing-masing. Atribut "c" untuk kunci "x" memiliki beberapa nilai terkait, jadi gunakan fungsi List.Max untuk mengatasi konflik.

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