Sum of all number combinations excluding repetition Excel

我们两清 提交于 2019-12-31 07:44:31

问题


this top voted answer Sum all combinations Excel or Google Spreadsheets is close to what I need - however I require a solution where it keeps the combinations in order and excludes repetition based on this order. i.e. a data set of 1 2 3 4 would show the product of:

1 1+2 1+3 1+4 1+2+3 1+2+4 1+3+4 1+2+3+4

2 2+3 2+4 2+3+4

3 3+4

4

i.e

1 3 4 5 6 10

2 5 6

3 7

4

Is this possible in Google Sheets / Excel without a script?

Thanks


回答1:


Here's a formula to display the sums in order

=ArrayFormula(sort(" "&transpose(split(SUBSTITUTE(substitute(textjoin("+",true,{if(mod(int(row(A1:A15)/(2^(column(A1:D1)-1))),2)=0,"",column(A1:D1)),B1:B15&";"}),"+;",";"),";+",";"),";")),1,true))

This formula will give the sum totals in the order that they are generated, but then it would have to be combined with the first formula to get them in the right order

=ArrayFormula(mmult(if(mod(int(row(A1:A15)/(2^(column(A1:D1)-1))),2)=0,0,column(A1:D1)),transpose(column(A1:D1))^0))

Giving this

=ArrayFormula(sort({" "&transpose(split(SUBSTITUTE(substitute(textjoin("+",true,{if(mod(int(row(A1:A15)/(2^(column(A1:D1)-1))),2)=0,"",column(A1:D1)),B1:B15&";"}),"+;",";"),";+",";"),";")),ArrayFormula(mmult(if(mod(int(row(A1:A15)/(2^(column(A1:D1)-1))),2)=0,0,column(A1:D1)),transpose(column(A1:D1))^0))},1,true))

Here's how it would look if you used actual values rather than column numbers

=ArrayFormula(sort({" "&transpose(split(SUBSTITUTE(substitute(textjoin("+",true,{if(mod(int(row(A1:A15)/(2^(column(A1:D1)-1))),2)=0,"",column(A1:D1)),if(row(A1:A15)>0,";")}),"+;",";"),";+",";"),";")),ArrayFormula(mmult(if(mod(int(row(A1:A15)/(2^(column(A1:D1)-1))),2)=0,0,A1:D1),transpose(column(A1:D1))^0))},1,true))



来源:https://stackoverflow.com/questions/50057104/sum-of-all-number-combinations-excluding-repetition-excel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!