Table.Pivot

语法

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

关于

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

示例 1

采用 ({ [ 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] })

示例 2

采用 ({ [ 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 ""