这种问题用powerquery处理要方便些
let
源 = Excel.CurrentWorkbook(){[Name="表1"]}[Content],
按分隔符拆分列 = Table.SplitColumn(源, "Reference", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"Reference.1", "Reference.2", "Reference.3", "Reference.4", "Reference.5", "Reference.6"}),
逆透视的其他列 = Table.UnpivotOtherColumns(按分隔符拆分列, {"PartNumber", "Comment", "QTY"}, "属性", "值"),
按分隔符拆分列1 = Table.SplitColumn(逆透视的其他列, "值", Splitter.SplitTextByDelimiter("-", QuoteStyle.Csv), {"值.1", "值.2"}),
已添加条件列 = Table.AddColumn(按分隔符拆分列1, "自定义", each if [值.2] = null then [值.1] else [值.2]),
删除的列 = Table.RemoveColumns(已添加条件列,{"值.2"}),
按照字符转换拆分列 = Table.SplitColumn(删除的列, "值.1", Splitter.SplitTextByCharacterTransition((c) => not List.Contains({"0".."9"}, c), {"0".."9"}), {"值.1.1", "值.1.2"}),
按照字符转换拆分列1 = Table.SplitColumn(按照字符转换拆分列, "自定义", Splitter.SplitTextByCharacterTransition((c) => not List.Contains({"0".."9"}, c), {"0".."9"}), {"自定义.1", "自定义.2"}),
更改的类型 = Table.TransformColumnTypes(按照字符转换拆分列1,{{"值.1.2", Int64.Type}, {"自定义.2", Int64.Type}}),
已添加自定义 = Table.AddColumn(更改的类型, "自定义", each {[值.1.2]..[自定义.2]}),
删除的列1 = Table.RemoveColumns(已添加自定义,{"值.1.2", "自定义.1", "自定义.2"}),
#"展开的“自定义”" = Table.ExpandListColumn(删除的列1, "自定义"),
合并的列 = Table.CombineColumns(Table.TransformColumnTypes(#"展开的“自定义”", {{"自定义", type text}}, "zh-CN"),{"值.1.1", "自定义"},Combiner.CombineTextByDelimiter("", QuoteStyle.None),"已合并"),
删除的列2 = Table.RemoveColumns(合并的列,{"属性"}),
分组的行 = Table.Group(删除的列2, {"PartNumber", "Comment", "QTY"}, {{"计数", each Text.Combine([已合并],"、"), type text}})
in
分组的行 |