Excel combinations from multiple columns with no duplicates

andrew_milonavic

Board Regular
Joined
Nov 16, 2016
Messages
98
Hi,

Is there a non VBA way to return all possible combinations without duplicates with the returned values in separate columns?

Example below. Data in the first 8 columns / 10 rows, results starting in the 11th column.

NoNoNo1NoNoNo1NoNoNo1NoNoNo1
YesYesYes2YesYesYes2YesNoNo1NoNoNo1
33
44
55
66
77
88
99
1010

<tbody>
</tbody>


Thanks

Andrew
 
Try:

Cell Formulas
RangeFormula
K1:M50K1=IF(ROW()>$T$1,"",IFERROR(INDEX(A:A,MOD(INT((ROW()-1)/PRODUCT(IFERROR(1/(1/SUBTOTAL(3,OFFSET(B:B,0,COLUMN(B:$I)-COLUMN(B:B)))),1))),COUNTA(A:A))+1),""))
T1T1=PRODUCT(IFERROR(1/(1/(SUBTOTAL(3,OFFSET(A:A,0,COLUMN(A:H)-COLUMN(A:A))))),1))
U1:U50U1=SUM(IF(MUNIT(COLUMNS($A$1:$H$1))<>1,($K1:$R1=TRANSPOSE($K1:$R1))*($K1:$R1<>""),0))+(ROW()>$T$1)
V1:X50V1=IFERROR(INDEX(K:K,AGGREGATE(15,6,ROW(K$1:INDEX(K:K,$T$1))/($U$1:INDEX($U:$U,$T$1)=0),ROW())),"")
Press CTRL+SHIFT+ENTER to enter array formulas.


T1 is just a formula to determine how many combinations there will be. I use it to determine a stopping condition for both the K1 and V1 formulas, as well as making the V1 formula more efficient. The U1 formula creates a helper column showing which rows have duplicates. Anything greater than 0 does. It'll also go above zero after it hits this maximum number of rows. It could be incorporated in the V1 formula, but you really don't want an array formula within an array formula. Then the V1 formula creates your list without the rows marked with a positive value in U.

See if this works for you.
 
Upvote 0

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Hi @Eric W

Could you please explain the first example. How did Row Number change from {1;1;2;2;1;1;2;2} to {1;1;1;1;2;2;2;2;1;1;1;1;2;2;2;2} as you move to next column.
I am not able to get strategy through evaluate formula option also
 
Upvote 0
Hi @Eric W

Could you please explain the first example. How did Row Number change from {1;1;2;2;1;1;2;2} to {1;1;1;1;2;2;2;2;1;1;1;1;2;2;2;2} as you move to next column.
I am not able to get strategy through evaluate formula option also
I'm not sure which example you're referring to. Which post number, and which cell number are you looking at?
 
Upvote 0
Hey @Eric W,

Is there a way to paste data into the data columns, in your example columns A-B-C, without the formula recognizing the blanks as duplicates?

Currently, if I paste your example data (A1:A5), the formula picks up the blanks from A4:B5 and then the results have blanks etc as they are being considered duplicates. Hope that makes sense?

Thoughts?

Thanks

Andrew
 
Upvote 0
Is there a way to paste data into the data columns, in your example columns A-B-C, without the formula recognizing the blanks as duplicates?

Currently, if I paste your example data (A1:A5), the formula picks up the blanks from A4:B5 and then the results have blanks etc as they are being considered duplicates. Hope that makes sense?
You're going to have to give me an example. There's a difference between an empty cell, and one with a space in it. The "duplicate" formula in U1 specifically ignores empty cells. Whenever I paste data in the A:H columns, I get the expected results, including spaces if they exist.
 
Upvote 0
Hey @Eric W,

Thanks for the fast reply!

I did a few tests. The problem appears to be because my data is compiled by an index match formula. Even though I have an IFNA and IF blank return blank in the statement apparently the cells still aren't blank.

Is there a work around for this? Or is my only option to copy and paste only the cells with data manually?

Thanks

Andrew
 
Upvote 0
Without seeing an example, I'd guess that the problem is with the SUBTOTAL (COUNTA) part of the formulas. COUNTA counts the number of "filled" cells in a range. It won't count an empty cell, but it will count a formula that returns an empty cell. There are ways to get around that, but it makes it tricky. Probably the easiest way would be to add 8 helper cells, each with the number of non-empty values in each of the A:H columns. You'd need to rearrange the layout in order to put them somewhere. I can also visualize another way using MMULT somehow (although I haven't worked out the details) where I could just update the existing formulas. But I'd be worried about performance.

Or like you said, you could copy/paste the values instead of using the INDEX/MATCH formula.
 
Upvote 0
Hey @Eric W,

I think I'll stick to copying it manually. It takes more time but you've already helped so much and removed all the heavy lifting that I don't mind some copy paste.

Thanks! Really appreciate the help

Andrew
 
Upvote 0
Hey @Eric W and Everyone,

It’s been awhile since I’ve been on Mr Excel, but I want to adjust a formula and can’t figure out how.

Previously Eric wrote this formula, and it works great, but I would like to add the functionality to prevent duplicates in the same row.

The original worked like this (Data on the left and combinations on the right).

Car1Car1Car1Car1Car2Car3
Car2Car2Car2Car1Car3Car2
Car3Car3Car3Car2Car1Car3
Car2Car3Car1
Car3Car1Car2
Car3Car2Car1



I would like it to work like this (Data on the left and combinations on the right):

Car1Car1Car1Car1Car2Car3
Car2Car2Car2
Car3Car3Car3


I would like to stick to formulas, and prefer not to use VBA’s.


Eric's Original Formula:
K1:M50K1=IF(ROW()>$T$1,"",IFERROR(INDEX(A:A,MOD(INT((ROW()-1)/PRODUCT(IFERROR(1/(1/SUBTOTAL(3,OFFSET(B:B,0,COLUMN(B:$I)-COLUMN(B:B)))),1))),COUNTA(A:A))+1),""))
T1T1=PRODUCT(IFERROR(1/(1/(SUBTOTAL(3,OFFSET(A:A,0,COLUMN(A:H)-COLUMN(A:A))))),1))
U1:U50U1=SUM(IF(MUNIT(COLUMNS($A$1:$H$1))<>1,($K1:$R1=TRANSPOSE($K1:$R1))*($K1:$R1<>""),0))+(ROW()>$T$1)
V1:X50V1=IFERROR(INDEX(K:K,AGGREGATE(15,6,ROW(K$1:INDEX(K:K,$T$1))/($U$1:INDEX($U:$U,$T$1)=0),ROW())),"")
Press CTRL+SHIFT+ENTER to enter array formulas.

Any help would be great!

Thanks

Andrew
 
Upvote 0

Forum statistics

Threads
1,214,608
Messages
6,120,500
Members
448,968
Latest member
screechyboy79

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