Share via


Table.Pivot

Sözdizimi

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

Hakkında

Öznitelik-değer çiftlerini temsil eden bir sütun çifti verlendiğinde, öznitelik sütunundaki verileri sütun başlıklarına döndürür.

Örnek 1

tablonun ({ [ key = "x", attribute = "a", value = 1 ], [ key = "x", attribute = "c", value = 3 ], [ key = "y", attribute = "a", value = 2 ], [ key = "y", attribute = "b", value = 4 ] }) öznitelik sütunundaki "a", "b" ve "c" değerlerini alıp kendi sütunlarında özetleyin.

Kullanım

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

Çıkış

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

Örnek 2

tablonun ({ [ 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 ] }) öznitelik sütunundaki "a", "b" ve "c" değerlerini alıp kendi sütunlarında özetleyin. "x" anahtarının "c" özniteliğiyle ilişkilendirilmiş birden çok değer vardır, bu nedenle çakışmayı çözmek için List.Max işlevini kullanın.

Kullanım

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
)

Çıkış

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