- let
- 源 = Excel.CurrentWorkbook(){[Name="表1"]}[Content],
- 合并标题 = [a=Table.Transpose(Table.FromColumns(List.Select(Table.ToColumns(Table.FirstN(源,3)),each List.Count(List.RemoveNulls(_))<>0))),b=Table.ColumnNames(a),c=Table.TransformColumnTypes(Table.FillDown(a,b),List.Zip({b,List.Repeat({type text},3)})),d=Table.Transpose(c),e=Table.ToColumns(d),f=List.Transform(e,each Text.Combine(_,","))][f],
- 合并列 = [a=Table.SelectRows(Table.FillDown(Table.Skip(源,4),{"列1"}),each [列2]<>null),b=Table.ToColumns(a),c=List.Transform(List.Split(List.Skip(b,3),2),List.Zip),d=Table.FromColumns(List.FirstN(b,3)&c,合并标题)][d],
- 逆透视 = [a=Table.Unpivot(合并列,List.Skip(Table.ColumnNames(合并列),3),"区分","值"),b=Table.SplitColumn(a,"区分",each Text.Split(_,","),{"日期","星期","早中晚"}),c=Table.SplitColumn(b,"值",each _,{"数量","金额"})][c],
- 重新排序 = Table.ReorderColumns(Table.Combine(Table.Group(逆透视,{"日期","星期","早中晚"},{"分组",each _})[分组]),{"日期", "星期", "早中晚", "分#(lf)类", "原料名称", "单价(元/g)", "数量", "金额"})
- in
- 重新排序
复制代码
|