Excel 365 - 从现有表创建新表以将每月数据标准化为单独的行
Posted
技术标签:
【中文标题】Excel 365 - 从现有表创建新表以将每月数据标准化为单独的行【英文标题】:Excel 365 - Create new table from existing one to normalize monthly data into separate rows 【发布时间】:2020-12-21 13:17:09 【问题描述】:我有一个数据集,其中包含带有如下列标题的销售信息:
Item# | Measure | Jan | Feb | Mar | *etc.*
我需要将表格转换为每个项目编号行包含度量类型、月份和每个度量的值。所以它看起来像这样:
Item# | Month | Measure_1 | Measure_2 | Measure_3 | *etc.*
我尝试在 Power Query 中取消透视,结果要么为空,要么返回偏斜。此外,我尝试将多个范围与数据透视表合并,但数据排列不正确。也许我可以在 Power BI 中运行 python 或 SQL 查询来得到这个?
【问题讨论】:
【参考方案1】:您可以像这样使用 Power Query 来做到这一点:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQ0MDA1VtJRCkotSczMATJMTS2BpKG5sQWQMjc1BZFmlkqxOkiK3XMTi9Iz84AsY2MQ39zSAEiamBqBSXNUxaF5mSXFIIPNgISRsQnYWBCBpi48NTM9owRkN0jWzBCk2gBCoKhzLk1KBakCGQmlDZViYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Item#" = _t, Type = _t, Jan = _t, Feb = _t, Mar = _t, Apr = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,"Item#", Int64.Type, "Type", type text, "Jan", Int64.Type, "Feb", Int64.Type, "Mar", Int64.Type, "Apr", Int64.Type),
#"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", "Item#", "Type", "Month", "Value"),
#"Pivoted Column" = Table.Pivot(#"Unpivoted Columns", List.Distinct(#"Unpivoted Columns"[Type]), "Type", "Value", List.Sum)
in
#"Pivoted Column"
以下两行可以解决问题:
#"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", "Item#", "Type", "Month", "Value"),
#"Pivoted Column" = Table.Pivot(#"Unpivoted Columns", List.Distinct(#"Unpivoted Columns"[Type]), "Type", "Value", List.Sum)
来源: 结果:
【讨论】:
如果答案有助于解决问题,请检查答案旁边的 ✓ 符号。以上是关于Excel 365 - 从现有表创建新表以将每月数据标准化为单独的行的主要内容,如果未能解决你的问题,请参考以下文章
如何有效地查询多个表以在 dataGrid 中生成 excel STYLE 报告