- let
- 源 = Excel.CurrentWorkbook(){[Name="表1"]}[Content],
- headers=List.RemoveFirstN(Table.ColumnNames(源),2),
- ls=List.Distinct(List.Transform(headers,each Text.Start(_,Text.Length(_)-4))),
- fx=(x as list,y as text)=>List.Select(x,each Text.Contains(_,y)),
- selcol={"货号","货名"},
- data=List.Transform(ls,each Table.SelectColumns(源,selcol &fx(headers,_))),
- fy=(x as table,y as text) as table=>[tb=Table.AddColumn(x,"地区",each y), ftb=Table.RenameColumns(tb,
- List.Zip({Table.ColumnNames(tb),selcol&{"库存数量","销售成本","库存周转","地区"}}))][ftb],
- fz=(x as list,y as text)=>List.Transform(x,each fy(_,y)),
- f=Table.Combine(List.Transform(ls,each fz(data,_){0}))
- in
- f
复制代码 |