|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
let
源 = Excel.CurrentWorkbook(){[Name="表1"]}[Content],
更改的类型 = Table.TransformColumnTypes(源,{{"编号", type text}, {"名称", type text}}),
删除的顶端行 = Table.Skip(更改的类型,1),
已添加自定义 = Table.AddColumn(删除的顶端行, "一级标题", each if Text.Contains([编号],"、") then [编号] else null),
筛选的行1 = Table.SelectRows(已添加自定义, each ([编号] <> null)),
向下填充 = Table.FillDown(筛选的行1,{"一级标题"}),
已添加自定义1 = Table.AddColumn(向下填充, "自定义", each if List.AllTrue({not List.IsEmpty(List.PositionOf({"0".."9"},[编号],2,(x,y)=>Text.Contains(y,x))),not List.IsEmpty(List.PositionOf({"一".."龟"},[编号],2,(x,y)=>Text.Contains(y,x)))}) then [编号] else null),
向下填充1 = Table.FillDown(已添加自定义1,{"自定义"}),
已添加自定义2 = Table.AddColumn(向下填充1, "自定义.1", each if List.IsEmpty(List.PositionOf({"0".."9","、"},[编号],2,(x,y)=>Text.Contains(y,x))) then [编号] else null),
向下填充2 = Table.FillDown(已添加自定义2,{"自定义.1"}),
筛选的行 = Table.SelectRows(向下填充2, each Text.Contains([编号],"Q")),
重排序的列 = Table.ReorderColumns(筛选的行,{"一级标题", "自定义", "自定义.1", "编号", "名称"}),
合并的列 = Table.CombineColumns(重排序的列,{"编号", "名称"},Combiner.CombineTextByDelimiter(" ", QuoteStyle.None),"编号及名称"),
分组的行 = Table.Group(合并的列, {"一级标题", "自定义", "自定义.1"}, {{"计数", each Text.Combine(Table.CombineColumns(Table.TransformColumnTypes(Table.AddIndexColumn(_,"a",1,1),{{"a", type text}}),{"a", "编号及名称"},Combiner.CombineTextByDelimiter("、", QuoteStyle.None),"已合并")[已合并],";")}}),
重命名的列 = Table.RenameColumns(分组的行,{{"自定义", "二级标题"}, {"自定义.1", "三级标题"}, {"计数", "内容"}})
in
重命名的列 |
|