0

我有这张桌子:

在此处输入图像描述

我想改成这样:

在此处输入图像描述

如您所见,我想将所有 P1 行、所有列中的所有相关条目收集到 P1 下的单个列中,并对 P2 和 P3 相关条目执行相同操作。

在 PowerQuery / M 中是否有一种简单的方法可以做到这一点?

4

1 回答 1

1

是的:

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"P", type text}, {"15", Int64.Type}, {"25", Int64.Type}, {"35", Int64.Type}, {"45", Int64.Type}, {"55", Int64.Type}, {"65", Int64.Type}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"P"}, "Attribute", "Value"),
    #"Removed Columns" = Table.RemoveColumns(#"Unpivoted Other Columns",{"Attribute"}),
    #"Grouped Rows" = Table.Group(#"Removed Columns", {"P"}, {{"AllData", each _, type table}}),
    TablesToLists = Table.TransformColumns(#"Grouped Rows",{{"AllData", each _[Value]}}),
    #"Transposed Table" = Table.Transpose(TablesToLists),
    #"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table", [PromoteAllScalars=true]),
    TableFromColumns = Table.FromColumns(Record.FieldValues(#"Promoted Headers"{0}),Table.ColumnNames(#"Promoted Headers"))
in
    TableFromColumns
于 2017-03-30T15:59:56.960 回答