+ Reply to Thread
Results 1 to 17 of 17

How to find every combination of two columns of data?

  1. #1
    Forum Contributor
    Join Date
    03-21-2013
    Location
    USA
    MS-Off Ver
    365
    Posts
    163

    How to find every combination of two columns of data?

    Can somebody help me figure out how to find every combination possible for 2 columns of data? The tricky part here has to do with the 2nd Columns list of data. This column has to be calculated to figure every combination of itself as well. This might be much easier to explain with an example. Below is an example of what I'm looking to do.

    Column A Column B
    A Apple
    B Banana
    C Orange
    D Pear
    Watermelon
    Kiwi
    Cantaloupe
    Strawberry
    Melon

    Results I'm looking for: (This example is only going to show all the results for 'A')
    A, Apple
    A, Banana
    A, Orange
    A, Pear
    A, Watermelon
    A, Kiwi
    A, Cantaloupe
    A, Strawberry
    A, Melon
    A, Apple, Banana
    A, Apple, Orange
    A, Apple, Pear
    A, Apple, Watermelon
    A, Apple, Kiwi
    A, Apple, Cantaloupe
    A, Apple, Strawberry
    A, Apple, Melon
    A, Apple, Banana, Orange
    A, Apple, Banana, Pear
    A, Apple, Banana, Watermelon
    ...
    ...
    ...
    ...
    ...
    ...
    A, Apple, Banana, Orange, Watermelon, Kiwi, Cantaloupe, Strawberry, Melon


    As you can see, doing this by hand is proving to be somewhat cumbersome and quite frankly, a huge waste of time that has many opportunities for human error. I'm hoping that there is somebody on here that has an easy solution for resolving this problem, because I am stumped, and my brain hurts from trying to figure it out.

    I guess I should also mention that the 'Column A' data will never need to be included in the subset combination sequence. Meaning, there will never be a result of "A, B, C, Apple, Banana, Orange, Watermelon....etc.". It will always only be an single cell of data from 'Column A' preceding each combination result from 'Col B'.

    Thank you in advance to whoever the certifiable genius is that can figure this out!

    -Mike in Sacramento, CA.

  2. #2
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 V 2504
    Posts
    13,733

    Re: How to find every combination of two columns of data?

    I'm assuming the comma separation is desired. Do I assume correctly?

    Edit Will this also include pattern like

    A, Banana, Orange
    A, Banana, Pear
    A, Banana, Watermelon

    etc.
    Last edited by FlameRetired; 06-22-2015 at 08:11 PM.
    Dave

  3. #3
    Forum Contributor
    Join Date
    03-21-2013
    Location
    USA
    MS-Off Ver
    365
    Posts
    163
    Quote Originally Posted by FlameRetired View Post
    I'm assuming the comma separation is desired. Do I assume correctly?
    Yes, that would be optimal.

  4. #4
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 V 2504
    Posts
    13,733

    Re: How to find every combination of two columns of data?

    OK. BTW: My edit crossed in the mail.

    Will this also include pattern like

    A, Banana, Orange
    A, Banana, Pear
    A, Banana, Watermelon

    etc.
    Last edited by FlameRetired; 06-22-2015 at 08:15 PM.

  5. #5
    Forum Contributor
    Join Date
    03-21-2013
    Location
    USA
    MS-Off Ver
    365
    Posts
    163

    Re: How to find every combination of two columns of data?

    If possible, yes. It's beyond my knowledge to figure out how to do that.

    Thank you so much FlameRetired for attempting to solve this. It is greatly appreciated.

  6. #6
    Forum Contributor
    Join Date
    03-21-2013
    Location
    USA
    MS-Off Ver
    365
    Posts
    163

    Re: How to find every combination of two columns of data?

    Am I allowed to 'bump' this? Since I first posted this question, I've continued to try and figure this out, but am still having no luck?

  7. #7
    Forum Expert Sam Capricci's Avatar
    Join Date
    06-14-2012
    Location
    Palm Harbor, Florida
    MS-Off Ver
    16.95 for Mac MS 365
    Posts
    8,690

    Re: How to find every combination of two columns of data?

    You certainly should bump the post if it isn't answered. Out of curiosity is a combination also A, banana, Apple, watermelon, so the same as one other just a different order?
    Make contributors happy, click on the "* Add Reputation" as a way to say thank you.
    Sam Capricci

  8. #8
    Forum Contributor
    Join Date
    03-21-2013
    Location
    USA
    MS-Off Ver
    365
    Posts
    163

    Re: How to find every combination of two columns of data?

    Hi Sambo! Your response is like a breath of fresh air. Or a glimmer of light at the end of my seemingly endless black hole of a tunnel...

    With that said, if you are asking me if it matters what order the Column B items are sorted in, then no, that does not matter. Or maybe I didn't understand your question. But, this problem is definitely centered solely around the combinations?

    I'm looking to have each item from Col A, combined with every possible combination of the items listed in Column B. In reference to my OP, I have A, B, C & D, listed in Col A. I guess I should have only shown 'A' in that Column, because in all reality, B, C & D's results, should end up looking identical to 'A's.

    Thank you so much for attempting to resolve this. If I can answer any other questions for you to help you better understand what I'm looking for, then please ask, and I will do my best to provide a clear response. Thanks again.

  9. #9
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: How to find every combination of two columns of data?

    There's a workbook at https://app.box.com/s/b9b9fc06beb63b9562f9 that would generate this from the list of fruits:

    Row\Col
    B
    C
    11
    m
    Apple Banana Orange Pear Watermelon Kiwi Cantaloupe Strawberry Melon
    12
    1
    Apple
    13
    1
    Banana
    14
    1
    Orange
    15
    1
    Pear
    16
    1
    Watermelon
    17
    1
    Kiwi
    18
    1
    Cantaloupe
    19
    1
    Strawberry
    20
    1
    Melon
    21
    2
    Banana Apple
    22
    2
    Orange Apple
    23
    2
    Orange Banana
    24
    2
    Pear Apple
    25
    2
    Pear Banana
    26
    2
    Pear Orange
    27
    2
    Watermelon Apple
    28
    2
    Watermelon Banana
    29
    2
    Watermelon Orange
    30
    2
    Watermelon Pear
    31
    2
    Kiwi Apple
    32
    2
    Kiwi Banana
    33
    2
    Kiwi Orange
    34
    2
    Kiwi Pear
    35
    2
    Kiwi Watermelon
    36
    2
    Cantaloupe Apple
    37
    2
    Cantaloupe Banana
    38
    2
    Cantaloupe Orange
    39
    2
    Cantaloupe Pear
    40
    2
    Cantaloupe Watermelon
    41
    2
    Cantaloupe Kiwi
    42
    2
    Strawberry Apple
    43
    2
    Strawberry Banana
    44
    2
    Strawberry Orange
    45
    2
    Strawberry Pear
    46
    2
    Strawberry Watermelon
    47
    2
    Strawberry Kiwi
    48
    2
    Strawberry Cantaloupe
    49
    2
    Melon Apple
    50
    2
    Melon Banana
    51
    2
    Melon Orange
    52
    2
    Melon Pear
    53
    2
    Melon Watermelon
    54
    2
    Melon Kiwi
    55
    2
    Melon Cantaloupe
    56
    2
    Melon Strawberry
    57
    3
    Orange Banana Apple
    58
    3
    Pear Banana Apple
    59
    3
    Pear Orange Apple
    60
    3
    Pear Orange Banana
    61
    3
    Watermelon Banana Apple
    62
    3


    Then you could take that list and use the workbook at https://app.box.com/s/47b28f19d794b25511be to generate the Cartesian product of those 511 items with the "A B C D".
    Entia non sunt multiplicanda sine necessitate

  10. #10
    Forum Contributor
    Join Date
    03-21-2013
    Location
    USA
    MS-Off Ver
    365
    Posts
    163

    Re: How to find every combination of two columns of data?

    Wow! Thanks SHG. This seems to pretty close to what I was looking for except that it seems to only apply to single word results. In my scenario, there will be many times where the item listed in Column B could have more than one word in it's cell. For example purposes only, one of the cells might say... "Big Red Apple", or "Small Green Apple". And sometimes it will say just... "Apple". Which is why I was hoping to separate the combo results with comma's for clarity when other people are viewing this.

    But, I really do appreciate you sharing that workbook with me SHG. I will definitely be looking into the macros written in there to see if I can learn anything that might help me.

    ----------------------

    I just looked at that Cartesian product, and I have to apologize. That looks very promising. I'm going to see what I can do with that.
    Last edited by xlyfe; 06-25-2015 at 12:58 PM. Reason: Premature response

  11. #11
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: How to find every combination of two columns of data?

    You're welcome, good luck.

  12. #12
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 V 2504
    Posts
    13,733

    Re: How to find every combination of two columns of data?

    Quote Originally Posted by mikerodrigueziii View Post

    I'm looking to have each item from Col A, combined with every possible combination of the items listed in Column B. In reference to my OP, I have A, B, C & D, listed in Col A. I guess I should have only shown 'A' in that Column, because in all reality, B, C & D's results, should end up looking identical to 'A's.
    Thank you for clarifying that part.

    Sorry I didn't get back to you. I was away for a while. Still not coming up with anything that does the job.

  13. #13
    Forum Contributor
    Join Date
    03-21-2013
    Location
    USA
    MS-Off Ver
    365
    Posts
    163

    Re: How to find every combination of two columns of data?

    Quote Originally Posted by FlameRetired View Post
    Thank you for clarifying that part.

    Sorry I didn't get back to you. I was away for a while. Still not coming up with anything that does the job.
    That's okay Flame. I completely understand. We all have our personal lives to attend to, and I wouldn't expect you to put some random guy from Sacramento above that. I'm grateful for any and all clues that I can receive from you geniuses. Even if I don't get exactly what I'm looking for, I'm pretty good about piecing together "similar/close" solutions until I can get what I'm looking for.

    In response to your second comment, I haven't found what I'm looking for just yet. Though, SHG did just share with me a workbook that might be very helpful to me. I'm currently playing around with that Cartesian Product workbook to see if it will do what I'm looking for. If it doesn't, I may just break down the formulas and see if I can rebuild them to work. So, as of this moment, no, I have not found a solution... yet.

  14. #14
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 V 2504
    Posts
    13,733

    Re: How to find every combination of two columns of data?

    Whew! I must say this was much more challenging than it first appeared.

    Some notes are in order.
    I named the ranges of fruits and the alphabetic data. They are Fruit_Stock and Alpha. I appended “ “ to the ends of both to accommodate the last concatenation/SUBSTITUTE step in column A.

    There is a sheet SampleOutput that I used as a reference so I could keep the patterns straight in my mind. It has no function beyond that so delete at will.

    Columns N:V are where I ‘dumbed out’ the indexing algorithm. They also have no function beyond that. I left them there in case they were helpful somehow.

    There are two helper rows …. C1:Q1 and C2:Q2. They are extended beyond what’s needed in order to accommodate more (or less) than 9 rows of “Fruits”.

    The formula for the repeating alphabet data in column B is
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    The formula for the fruits is parsed in columns C:K. It is:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    I put line breaks in it hoping to make it more readable.

    The file is attached.

    Now I am going to follow the links shg posted and find out what a Cartesian product is .... LOL.
    Attached Files Attached Files

  15. #15
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,710

    Re: How to find every combination of two columns of data?

    Pl see attached file with macro.
    Attached Files Attached Files

  16. #16
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,840

    Re: How to find every combination of two columns of data?

    Another version .....
    Attached Files Attached Files

  17. #17
    Registered User
    Join Date
    05-31-2015
    Location
    UK
    MS-Off Ver
    MS Office
    Posts
    1

    Re: How to find every combination of two columns of data?

    I think if you simple merge two colunm it will work.
    Here is an example.
    combined-names.png

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 9
    Last Post: 12-03-2014, 04:47 AM
  2. Replies: 1
    Last Post: 02-20-2014, 12:24 PM
  3. [SOLVED] Find specific data combination on another sheet using command button.
    By Ataraxicatom in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-08-2012, 09:55 AM
  4. [SOLVED] Combination of Data in two columns
    By srikanthk in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-04-2012, 01:01 AM
  5. Find Best Combination based on two columns
    By bountyHunter03 in forum Excel General
    Replies: 6
    Last Post: 05-01-2012, 02:01 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1