Excel Power Query 解耦和逆透视列

Excel Power Query decouple and unpivot columns

我有一个与此类似的数据结构

| type | A-metric1 | A-metric2 | B-metric1 | B-metric2 |
| aRow |     1     |     2     |     3     |     4     |

我想把 A 和 B 变成一个维度,然后把它变成行,这样就变成这样了

| type | dimension | metric1 | metric2 |
| aRow |     A     |    1    |    2    |
| aRow |     B     |    3    |    4    |

我可能可以通过复制类型行的次数与维度标签的次数一样多来手动执行此操作,然后按顺序提取指标并在 excel 中使用宏执行此操作。

但是我可能要处理大文件,并且可能无法在 VBA 中有效地处理这种大小的数据。我想知道在 Excels Power Query / Get & Transform 中是否可以做这样的事情?

抱歉,如果重复 - 我不确定如何提出这个问题以获得相关的搜索结果。

您可以采用以下方法:

let
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    unpivot = Table.UnpivotOtherColumns(Source, {"type"}, "Attribute", "Value"),
    split = Table.SplitColumn(unpivot, "Attribute", Splitter.SplitTextByDelimiter("-", 1), {"dimension", "metric"}),
    pivot = Table.Pivot(split, List.Distinct(split[metric]), "metric", "Value")
in
    pivot