Table.Pivot

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

给定一对表示属性-值对的列,将属性列中的数据旋转为列标题。

示例:

选取表 ({ [ 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",并将它们透视为其自己的列。

使用情况:

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")

输出:

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

示例:

选取表 ({ [ 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",并将它们透视为其自己的列。 键 "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)

输出:

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

results matching ""

    No results matching ""