Table.Pivot
Dado un par de columnas que representan parejas atributo-valor, rota los datos de la columna de atributo en los encabezados de columna.
Syntax
Table.Pivot(
table as table,
pivotValues as list,
attributeColumn as text,
valueColumn as text,
optional aggregationFunction as function
) as table
Remarks
Dado un par de columnas que representan parejas atributo-valor, rota los datos de la columna de atributo en los encabezados de columna.
Examples
Example #1
Tomar los valores "a", "b" y "c" en la columna de atributo de la tabla <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> y dinamizarlos en su propia columna.
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
Tomar los valores "a", "b" y "c" en la columna de atributo de la tabla <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> y dinamizarlos en su propia columna. El atributo "c" para la clave "x" tiene varios valores asociados, por lo que usa la función List.Max para resolver el conflicto.
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