简体   繁体   English

Excel Power Query解耦和取消透视列

[英]Excel Power Query decouple and unpivot columns

I have a data structure that is something comparable to this 我有一个与此类似的数据结构

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

I'd like to turn A and B into a dimensions and turn it into rows so that it's something like this 我想将A和B变成一个尺寸并将其变成行,这样就可以了

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

I could probably do this manually by duplicating the type row for as many times as there are dimension labels, and then extract the metrics by order and do this in excel with a macro. 我可以通过将类型行复制与维度标签一样多的次数来手动执行此操作,然后按顺序提取指标并在excel中使用宏执行此操作。

However I am likely to be handling large files, and probably can't manipulate data of this size effecitvely in VBA. 但是,我可能正在处理大型文件,并且可能无法在VBA中有效地处理这种大小的数据。 I was wondering if something like this is possible to do in Excels Power Query / Get & Transform? 我想知道在Excels Power Query / Get&Transform中是否可以做类似的事情?

Sorry if duplicate - Im not sure how to formulate this question to get relevant hits on searches. 很抱歉,如果有重复-我不确定如何提出这个问题来获得相关的搜索匹配。

You may apply following approach: 您可以采用以下方法:

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

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM