透视问题
源和结果图
let
源 = Excel.CurrentWorkbook(){[Name="表2"]}[Content],
更改的类型 = Table.TransformColumnTypes(源,{{"列1", type text}, {"列2", type text}, {"列3", type any}, {"列4", type any}, {"列5", type any}}),
向下填充 = Table.FillDown(更改的类型,{"列1", "列2"}),
转置表 = Table.Transpose(向下填充),
合并的列 = Table.CombineColumns(Table.TransformColumnTypes(转置表, {{"Column1", type text}}, "zh-CN"),{"Column1", "Column2"},Combiner.CombineTextByDelimiter(",", QuoteStyle.None),"已合并"),
转置表1 = Table.Transpose(合并的列),
提升的标题 = Table.PromoteHeaders(转置表1, [PromoteAllScalars=true]),
更改的类型1 = Table.TransformColumnTypes(提升的标题,{{",", type text}, {",_1", type text}, {"2018,Actual", Int64.Type}, {"2019,Actual", Int64.Type}, {"2020,Forecast", Int64.Type}}),
筛选的行 = Table.SelectRows(更改的类型1, each ([#",_1"] <> null)),
逆透视的列 = Table.UnpivotOtherColumns(筛选的行, {",", ",_1"}, "属性", "值"),
按分隔符拆分列 = Table.SplitColumn(逆透视的列, "属性", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"属性.1", "属性.2"}),
更改的类型2 = Table.TransformColumnTypes(按分隔符拆分列,{{"属性.1", Int64.Type}, {"属性.2", type text}}),
重命名的列 = Table.RenameColumns(更改的类型2,{{",", "type"}, {",_1", "Categorie"}, {"属性.1", "date"}, {"属性.2", "Status"}, {"值", "Amount"}})
in
重命名的列
步骤截图:
?了
自由转载-非商用-非衍生-保持署名(创意共享3.0许可证)