excel - Excel / Powerquery:重塑和转置表格的一部分
问题描述
我有一个这样的表,我使用 powerquery 构建了来自不同地方的大量数据。
现在我被困在尝试转置其中的一部分,同时保持主列不变。我需要将其更改为以下格式,以便通过我无法更改的不同脚本进行进一步处理。
它可以是简单的 excel 或 powerquery,甚至可以是 VB 脚本。任何可以解决问题的东西。
谢谢
解决方案
您可以在 Power Query 中执行以下操作:
1) 反透视除客户和月份以外的列
2)以值作为值列的枢轴月份
如下面的代码
let
Source = Excel.CurrentWorkbook(){[Name="Table7"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Customer", type text}, {"Month", type text}, {"Revenue", type number}, {"Product 1", type number}, {"Product 2", type number}, {"Product 3", type number}}),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Customer", "Month"}, "Attribute", "Value"),
#"Pivoted Column" = Table.Pivot(#"Unpivoted Other Columns", List.Distinct(#"Unpivoted Other Columns"[Month]), "Month", "Value", List.Sum)
in
#"Pivoted Column"
推荐阅读
- ios - ITMS-90809:不推荐使用的 API 使用 - 不再接受使用 UIWebView 的现有应用程序
- android - 解压缩 Android 应用程序包并再次压缩
- java - 如何仅通过重新排列链接来重新排列 Java 中的 LinkedList 而不更改数据字段?
- node.js - Angular 6 ng 服务在生产中的某个时间后失败
- linux - 关于服务器、端口和横幅抓取的问题
- python - 如何以嵌套的 dict 格式对值进行排序?
- android - 以编程方式向 RecyclerView 项添加一些视图会创建一个已知错误
- owin - 注销请求导致错误
- database - MongoDb 数据库更新时如何立即更新烧瓶前端?
- reactjs - React 中超过 24 小时的时间选择器