- let
- 源 = Excel.CurrentWorkbook(){[Name="表1"]}[Content],
- 更改的类型 = Table.TransformColumnTypes(源,{{"月份", type text}, {"款号", type text}, {"销量", Int64.Type}, {"销额", type number}}),
- 分组的行 = Table.Group(更改的类型, {"款号", "月份"}, {{"计数", each {List.Sum(_[销量]),List.Sum(_[销额])}}}),
- 已透视列 = Table.Pivot(分组的行, List.Distinct(分组的行[月份]),"月份","计数"),
- a = List.Transform(
- Table.ToRows(已透视列),
- each {_{0}} & List.Combine(
- List.Transform(
- List.Skip(_),
- (y)=>if y=null then {null,null} else y
- )
- )
- ),
- b = List.ReplaceValue(
- List.Accumulate(
- {1.. List.Count(Table.ColumnNames(已透视列))-1},
- Table.ColumnNames(已透视列),
- (s,c)=>List.InsertRange(
- s,
- 2*c,
- {null}
- )
- ),
- "款号",
- "",
- Replacer.ReplaceText
- ),
- c = {"款号"}&List.Repeat({"销量","销额"},(List.Count(b)-1) /2),
- 自定义1 = Table.FromRows({b}&{c}&a)
- in
- 自定义1
复制代码
|