let
fx=(x as list,y as number) as list =>
let
L=Table.Buffer(Table.Group(表1, {"订单号"}, {"组合", each [商品代码]})),
K=List.Buffer(表1[商品代码]),
A=List.RemoveLastN(x,y-1),
fx2=(x1 as list,y1 as number)=>
let
V=if y1=y then x1 else @fx2(S,y1+1),
S=List.TransformMany(x1,each List.Skip(List.RemoveFirstN(x,(n)=>n<>_),1),(g,u)=>[商品A=g,
商品B=u,
包含A的订单数=List.Count(List.PositionOf(K,g,2)),
包含B的订单数=List.Count(List.PositionOf(K,u,2)),
#"同时包含A+B的订单数"=Table.RowCount(Table.SelectRows(L,(x)=>List.ContainsAll(x[组合],{g,u}))),
总订单数=List.Count(List.Distinct(表1[订单号]))
])
in
V
in
fx2(A,1)
in
Table.FromRecords(fx(List.Distinct(表1[商品代码]),2))