【发布时间】:2017-04-27 17:43:25
【问题描述】:
源数据表。
期望的输出
我们想从每个类型列中提取所有唯一值并将唯一值作为列标题。
与此有些相似,但我们有不止一列来查找唯一值。 Power Query - Transpose unique values and get matching values in rows
Source 表中的 Type 列数会随着时间的推移而增加或减少。
【问题讨论】:
源数据表。
期望的输出
我们想从每个类型列中提取所有唯一值并将唯一值作为列标题。
与此有些相似,但我们有不止一列来查找唯一值。 Power Query - Transpose unique values and get matching values in rows
Source 表中的 Type 列数会随着时间的推移而增加或减少。
【问题讨论】:
下面的代码是通过标准菜单选项创建的。 This video 带你了解每一步的结果。
let
Source = SourceData,
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"Key"}, "Attribute", "Value"),
#"Added Custom" = Table.AddColumn(#"Unpivoted Other Columns", "Type", each if Text.Start([Attribute],4) = "Type" then [Value] else null),
#"Filled Down" = Table.FillDown(#"Added Custom",{"Type"}),
#"Filtered Rows" = Table.SelectRows(#"Filled Down", each not Text.StartsWith([Attribute], "Type")),
#"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Attribute"}),
#"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[Type]), "Type", "Value")
in
#"Pivoted Column"
【讨论】: