MAKECOMBO

=MAKECOMBO(array1,array2)

array1
First array to make combination
array2
Second array to make combination

Returns combination of two arrays

gifariz

Board Regular
Joined
May 2, 2021
Messages
120
Office Version
  1. 365
Platform
  1. Windows
MAKECOMBO

Function: Returns combination of two arrays

Excel Formula:
=LAMBDA(array1,array2,LET(a,array1,b,array2,La,COUNTA(a),Lb,COUNTA(b),MAKEARRAY(La*Lb,2,LAMBDA(r,c,IF(c=1,INDEX(a,INT((r-1)/Lb)+1),INDEX(b,MOD(r-1,Lb)+1))))))

Here is example (attached image)
1666323672233.png


This is my first lambda function posted here. Kindly please give your suggestions. Thanks.
I use "make" word in the function name to avoid confusion with Combination only that usually refer to number of combinations of two groups in Mathematics.
 
Upvote 0
Hello everyone,

my solution

Rang A rang B
A 5
B 6
C 7
8

=MID(TOCOL(MAKEARRAY(counta(A1:A3), counta(B1:B4),LAMBDA(x,y,IF(x,INDEX(A1:A3,x))&IF(y,INDEX(B1:B4,y))))),{1,2},1)

I hope it works well!

David
 
This is cool, because you realized that the function will be slow for large data, but the reason for that is MAKEARRAY itself, with or without LET.
Your function is designed for 2 vectors only, (not 2D arrays) and for that you do not need MAKEARRAY at all.
New lambda helper functions are kind of iterative algorithms that should be used only when there is no other option. (if you care about efficiency)
An alternative, no MAKEARRAY, for 2 vectors:
COMB2V(va,vb) Combine 2 Vectors
Excel Formula:
=LAMBDA(va,vb,LET(r,COUNTA(va),c,COUNTA(vb),s,SEQUENCE(r*c),q,QUOTIENT(s-1,c)+1,m,MOD(s-1,c)+1,IF({1,0},INDEX(va,q),INDEX(vb,m))))
The Big O using your function for 2 vectors, n elements each will be O(2n^2) => O(n^2) vs O() for COMB2V, will be O(2)
Simple example: define v=sequence(1000) Calc time for MAKECOMBO(v,v) is over 30 seconds, calc time for COMB2V(v,v) or ACOMB(HSTACK(v,v)) => instant (less than 1s)
Hope that helps, and sorry for my comments, I felt like I was somehow "invited". Keep creating functions. Does not matter if a function was previously done or not. ✌️
Wow this is super cool. I didn't know IF function can have array input for the arguments.
Many thanks also for saying lambda helper functions are slow. I need to remake all my sheets again reflecting this info to remove all unnecessary lambda helper functions, because they are really slow now.

Yeah, sorry I couldn't find your functions before I post this. But for me actually the important information from discussion like this is more important than the function itself. That's why I ask for suggestions in the post. Thank you for coming here.

One question while we are at topic of efficiency, I notice sometimes these functions is much faster than the other:
- OFFSET is faster than INDEX to retrieve value from large array.
- XLOOKUP is faster than INDEX-MATCH.
- XMATCH is faster than MATCH in ordered array.
Are all of these generally true? What do you think?

And any reason you use QUOTIENT instead of INT?
 
Last edited:
Hi Xlambda,

Sorry for my English, not my native language, I don't know if you noticed, in the Makearray function, in the last part, you can use (x,y,x) or (x,y,y), and together (x,y,x&y), =Tocol(MAKEARRAY(rang(A),rang( B),LAMBDA(x,y,x&y))),or =Tocol(MAKEARRAY(rang(A),rang( B),LAMBDA(x,y,x))),,1) and so.
For this type of scenarios, I will still use what I have used before makearray came: =sequence(x)&sequence(,y)
If it is easier for you, use it, nothing wrong with it.
Book1
ABCDEFGHI
1Without MAKEARRAY
2
3=SEQUENCE(3)&SEQUENCE(,4)=TOCOL(B4#)
41112131411
52122232412
63132333413
714
821
922
1023
1124
1231
1332
1433
1534
16
Sheet2
Cell Formulas
RangeFormula
B3,G3B3=FORMULATEXT(B4)
B4:E6B4=SEQUENCE(3)&SEQUENCE(,4)
G4:G15G4=TOCOL(B4#)
Dynamic array formulas.
 
Hi Xlambda,

I just recently started learning about lambda, and I am most interested in performance and efficiency. You probably know that it can be solved in several ways, and you will also agree with me that the solution I gave and the last substitution you gave are better than the function COMB2V.
I believe that simple functions are more effective.
 
Many thanks also for saying lambda helper functions are slow.
I do not know if "slow" is the right, fair word for it. I think I found a better way to describe it.
Imagine the elevators in a super tall skyscraper building. They are all the same make, they use the same infrastructure of rails, mechanics, and electronics.
Some of them, the regular ones, can be programed to access any floor, and some of them can be programmed to acces every other 20 floors, the express ones,
When they are moving, they are equally fast.
If the only task is to get to the 20th floor, take the express, if you take the regular you risk stopping on each floor even if no information is getting in, no information is getting out.
Waste of resources, looks and feels slow.
At the end of the day, the regular ones (lambda helpers), when really needed, can carry more complex information for complex tasks, outperforming the express ones.
One question while we are at topic of efficiency, I notice sometimes these functions is much faster than the other:
- OFFSET is faster than INDEX to retrieve value from large array.
- XLOOKUP is faster than INDEX-MATCH.
- XMATCH is faster than MATCH in ordered array.
Are all of these generally true? What do you think?
Speed test results are very contextual. It is not complicated to construct your own tests. The only thing you have to consider is to compare binary with binary, exact with exact.
INDEX-MATCH binary can be lot faster than XLOOKUP exact. Golden rule: Whenever you can sort always use binary lookups of any function you like.
And any reason you use QUOTIENT instead of INT?
Personal thing, I felt sorry for the quotient function that nobody uses it. MOD and QUOTIENT are brothers, they have same parents (identical arguments). In my functions/formulas they will never be separated. 😉
Yeah, sorry I couldn't find your functions before I post this.
As I said before, you do not have to find or follow anything. This new Excel ecosystem is new to all of us. It is too early to develop any stereotypes. Have an idea you believe in, go for it.
Think of it as a library. You do not need to read any books to write your own novel.
more important than the function itself.
Regarding the function, I am planning to explain better the concept behind ACOMB and all combinatorics calculations, on future posts, but probably not here.
There is a simple formula/function that is the main core of solving any combinatorics problem, permutations, combinations, combinations of n vectors...etc
fn(n,c)=LAMBDA(n,c,MOD(ROUNDUP(SEQUENCE(n^c)/n^(c-SEQUENCE(,c)),0)-1,n)+1)
 
=Tocol(MAKEARRAY(counta(A),counta( B),LAMBDA(x,y,x&y))) 2 times faster than COMB2V, at least, if I'm wrong, I don't believe anything anymore.😉
 
=MID(TOCOL(MAKEARRAY(counta(A1:A3), counta(B1:B4),LAMBDA(x,y,IF(x,INDEX(A1:A3,x))&IF(y,INDEX(B1:B4,y))))),{1,2},1)

I hope it works well!

David
Sorry but it doesn't!! Formula as it is, can handle correctly only vectors single chars up to 9 elements.
Problem to solve: If you append Aa and 10 you get Aa10, MID extraction only first 2 chars will be A,a and not Aa, 10
Book1
ABCDEFGHIJKLMNOPQRSTU
1Aa5
2Bb6=MID(TOCOL(MAKEARRAY(COUNTA(A1:A4), COUNTA(B1:B4),LAMBDA(x,y,IF(x,INDEX(A1:A4,x))&IF(y,INDEX(B1:B4,y))))),{1,2},1)
3C7Aa
4DAa
5Aawrong
6BbOK
7Bb
8Bb
9C5
10C6
11C7
12D5
13D6
14D7
15
16=MID(TOCOL(MAKEARRAY(COUNTA(A17:A21), COUNTA(B17:B27),LAMBDA(x,y,IF(x,INDEX(A17:A21,x))&IF(y,INDEX(B17:B27,y))))),{1,2},1)
17Aa1Aa
18B2AaCOMB2V
19C3Aa=LAMBDA(va,vb,LET(r,COUNTA(va),c,COUNTA(vb),s,SEQUENCE(r*c),q,QUOTIENT(s-1,c)+1,m,MOD(s-1,c)+1,IF({1,0},INDEX(va,q),INDEX(vb,m))))(A17:A21,B17:B27)
20D4AaAa1
21E5AaAa2
226AaAa3
237AaAa4
248AaAa5
259AaAa6
2610AaAa7
2711AaAa8
28B1Aa9
29B2Aa10
30B3Aa11
31B4B1
32B5B2
33B6B3
34B7B4
35B8B5
36B9B6
37B1B7
38B1B8
39C1B9
40C2B10
41C3B11
42C4C1
43C5C2
44C6C3
45C7C4
46C8C5
47C9C6
48C1C7
49C1C8
50D1C9
51D2C10
52D3C11
53D4D1
54D5D2
55D6D3
56D7D4
57D8D5
58D9D6
59D1D7
60D1D8
61E1D9
62E2D10
63E3D11
64E4E1
65E5E2
66E6E3
67E7E4
68E8E5
69E9E6
70E1E7
71E1E8
72E9
73E10
74E11
75
Sheet1
Cell Formulas
RangeFormula
D2,G19,D16D2=FORMULATEXT(D3)
D3:E14D3=MID(TOCOL(MAKEARRAY(COUNTA(A1:A4), COUNTA(B1:B4),LAMBDA(x,y,IF(x,INDEX(A1:A4,x))&IF(y,INDEX(B1:B4,y))))),{1,2},1)
D17:E71D17=MID(TOCOL(MAKEARRAY(COUNTA(A17:A21), COUNTA(B17:B27),LAMBDA(x,y,IF(x,INDEX(A17:A21,x))&IF(y,INDEX(B17:B27,y))))),{1,2},1)
G20:H74G20=LAMBDA(va,vb,LET(r,COUNTA(va),c,COUNTA(vb),s,SEQUENCE(r*c),q,QUOTIENT(s-1,c)+1,m,MOD(s-1,c)+1,IF({1,0},INDEX(va,q),INDEX(vb,m))))(A17:A21,B17:B27)
Dynamic array formulas.
 
=Tocol(MAKEARRAY(counta(A),counta( B),LAMBDA(x,y,x&y))) 2 times faster than COMB2V, at least, if I'm wrong, I don't believe anything anymore.😉
Sorry again, as it is, without the correction, your formula is the slowest of all 3. And, after the correction, it will be even slower.
Same conclusion, same thread, twice, if you care about performance, do not use MAKEARRAY for simple tasks when is not needed.
Book1
ABCDEFGHIJKLMNOPQRSTU
1calc time 34.55 sec5.7 sec slower than MAKECOMBO
2=MID(TOCOL(MAKEARRAY(COUNTA(SEQUENCE(1000)), COUNTA(SEQUENCE(1000)),LAMBDA(x,y,IF(x,INDEX(SEQUENCE(1000),x))&IF(y,INDEX(SEQUENCE(1000),y))))),{1,2},1)
311
412COMB2V calc time 0.93 sec
513=LAMBDA(va,vb,LET(r,COUNTA(va),c,COUNTA(vb),s,SEQUENCE(r*c),q,QUOTIENT(s-1,c)+1,m,MOD(s-1,c)+1,IF({1,0},INDEX(va,q),INDEX(vb,m))))(SEQUENCE(1000),SEQUENCE(1000))
61411
71512
81613check if arrays same row nr.
91714
101815=ROWS(B3#)=ROWS(E6#)
111916TRUE
121117
131118
141119
1511110
1611111
1711112
1811113
1911114
2011115
2111116
2212117
2312118
2412119
2512120
2612121
2712122
2812123
2912124
3012125
3112126
3213127
3313128
3413129
3513130
3613131
3713132
3813133
3913134
4013135
4113136
4214137
4314138
4414139
4514140
4614141
4714142
4814143
Sheet2
Cell Formulas
RangeFormula
B2,H10,E5B2=FORMULATEXT(B3)
B3:C1000002B3=MID(TOCOL(MAKEARRAY(COUNTA(SEQUENCE(1000)), COUNTA(SEQUENCE(1000)),LAMBDA(x,y,IF(x,INDEX(SEQUENCE(1000),x))&IF(y,INDEX(SEQUENCE(1000),y))))),{1,2},1)
E6:F1000005E6=LAMBDA(va,vb,LET(r,COUNTA(va),c,COUNTA(vb),s,SEQUENCE(r*c),q,QUOTIENT(s-1,c)+1,m,MOD(s-1,c)+1,IF({1,0},INDEX(va,q),INDEX(vb,m))))(SEQUENCE(1000),SEQUENCE(1000))
H11H11=ROWS(B3#)=ROWS(E6#)
Dynamic array formulas.
 

Forum statistics

Threads
1,223,575
Messages
6,173,148
Members
452,502
Latest member
PQCurious

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top