在原有的代码上加工了下,做了一个通用性的自定义函数。
let
fx_all=(o as number, p as number, replace_list as list)=>
//replace_list是需要进行组合的列表数据。
let
origian_list={1..end_number},
end_number=List.Count(replace_list),
fx=(table as table, origian_list as list, replace_list as list, column_name as text)=>
List.Accumulate(List.Zip({origian_list,replace_list}),table,(x,y)=>Table.ReplaceValue(x,y{0},y{1},Replacer.ReplaceText,{column_name})),
fx1=(o as number,p as number,end_number as number)=>
//o代表组合位数,0代表只有一位组合。p代表组合位数结束,如果只需要2位组合,则o和p都为1。
List.Combine(
List.Transform({o..p}, //o代表组合位数
(z)=>List.Accumulate({1..z},
List.Zip({{1..end_number}}),
(x,y)=>List.TransformMany(x,
each {_{y-1}+1..end_number},
(a,b)=>a&{b}
)
)
)
),
自定义1 = fx1(o,p,end_number),
转换为表 = Table.FromList(自定义1, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
提取值 = Table.TransformColumns(转换为表, {"Column1", each Text.Combine(List.Transform(_, Text.From)), type text}),
origian_list_new=List.Transform(origian_list, Text.From),
替换的值 = List.Accumulate(List.Zip({origian_list_new,replace_list}),提取值,(x,y)=>Table.ReplaceValue(x,y{0},y{1},Replacer.ReplaceText,{"Column1"}))
in
替换的值,
元数据=[Documentation.Name="批量组合",
Documentation.Description="通过组合方式进行排列,o,p代表组合位数,0代表1位数组合,如果o和p都为1,则只排序2位组合,replace_list是需要进行组合的列表数据。",
Documentation.Examples={[Description="把{1,2,3}组合成{1,2,3,12,13,23}",
Code="fx(0,2,{1,2,3})",
Result="{1,2,3,12,13,23}"],
[Description="把{""a"",""b"",""c""}组合成{""ab"",""ac"",""bc"",""abc""}",
Code="fx(1,2,{""a"",""b"",""c""})",
Result="{""ab"",""ac"",""bc"",""abc""}"]
}
]
in
Value.ReplaceType(fx_all,Value.Type(fx_all) meta 元数据)