# Getting every combination of 4 items from a unique list

I have a list of items that looks like this : The goal would be to get every unique combination of 4 of those items.
The combinations are unordered so ABCD, BADC, DBAC, etc. are considered the same result and only one of them should appear.

With this example, the result should look like this : With only 5 items it's quite easy to calculate in your head, but my real project has 18 of those items, which means there is 3060 combinations ...

The ideal output would be 1 item per column but this isn't that important as I can still separate them later if needed.

I don't mind having to setup a new sheet only for the calculations.

• Welcome. We already have related questions like Show all combinations for a selection of columns. If you need further help, please add a brief description of you search/research efforts as is suggested by How to Ask.
– Rubén
Oct 25 '19 at 15:24
• All related questions I could find were about several sets of items in several columns, with items from the same column not mixing up with each others. My question is literally the opposite thing.
– Runj
Oct 25 '19 at 16:36
• Have you learned something of those questions that you already read? What kind of solution are you looking for, one formula based or one based on using a script?
– Rubén
Oct 25 '19 at 16:39
• I'd be more looking for a formula based one
– Runj
Oct 25 '19 at 16:41

Formula

`=ArrayFormula(SPLIT(REPLACE(IFERROR(ROW(1:5)/0,)&A1:A5&","&JOIN(",",TRANSPOSE(A1:A5)),ROW(1:5)*2,2,""),","))`

How it works

The core logic is to create a transposed copy of the values of `A1:A5` for each element of `A1:A5` then remove the first element for the first copy , the second element of the second copy, and so on, then join `A1:A5` with the corresponding copy.

The formula use the concatenate operator (`&`), the multiplication operator (`*`), division operator (`/`),`TRANSPOSE`, `ROW`, `JOIN`, `SPLIT`, `REPLACE`,`IFERROR` and `ARRAYFORMULA`.

NOTES

If your real values use commas, on each instance of `","` replace the comma by another character (it could be an emoji or any other Unicode character)

If the formula will be placed in a row that is not the first one, then you should use the addition operator `+` to compensate the position.

If the real values have more than one character, the number 2 in the formula should be replaced by another value.

Related