【问题标题】:How can I transpose only some columns of a table in power query?如何在电源查询中仅转置表的某些列?
【发布时间】:2021-11-30 07:35:48
【问题描述】:

我在电源查询中有一个这样的表:

Date Name OutputType Group1 Group2 Group3 ...
01/10/2021 A Type1 565 63521 651 ...
01/10/2021 A Type2 6546 6541 13286 ...
01/10/2021 B Type1 0 5 685 ...
01/10/2021 B Type2 564 0 65 ...
... ... ... ... ... ... ...

我要做的是仅“转置” OutputType 和 Group 标题,以便我的所有组都在一个列中,并且我的 OutputTypes 成为标题。像这样的:

Date Name GroupTypes Type1 Type2
01/10/2021 A Group1 541 984
01/10/2021 A Group2 8971 6526
01/10/2021 B Group3 321 98
01/10/2021 B Group4 564 845
... ... ... ... ...

我尝试取消透视列,但我只得到部分结果,因为我的所有组类型都变成了一个列。但我无法将我的 OutputType 值“转换”为标题。

有人知道如何在电源查询中实现这一点吗?

对不起,如果我的问题不是很清楚,我的英语不是最好的。

感谢您的帮助!

【问题讨论】:

  • 您能否不只是取消透视组,然后将输出类型作为下一步进行透视?

标签: excel powerquery transpose


【解决方案1】:

单击选择日期、名称和输出类型

右键取消透视其他列

单击选择输出类型列

转换 .. 透视列 ... 并选择 Value 作为值列

let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"Date", "Name", "OutputType"}, "Attribute", "Value"),
#"Pivoted Column" = Table.Pivot(#"Unpivoted Other Columns", List.Distinct(#"Unpivoted Other Columns"[OutputType]), "OutputType", "Value", List.Sum)
in #"Pivoted Column"

【讨论】:

    猜你喜欢
    • 2016-07-08
    • 1970-01-01
    • 1970-01-01
    • 2017-02-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-10
    相关资源
    最近更新 更多