+ Reply to Thread
Results 1 to 8 of 8

Every Combination of string from 4 columns

  1. #1
    Forum Contributor
    Join Date
    08-02-2015
    Location
    Canada
    MS-Off Ver
    Office 2010
    Posts
    129

    Every Combination of string from 4 columns

    Hello,

    I have 4 columns of account segments. I would like have every possible combination of strings that can be assembled. The order of assembly should be......... segment 1 - segment 2 - segment 3 - segment 4
    Would it also be possible to have the output in this format:

    Example: 10-200-50020-7900

    Thank you very much
    Attached Files Attached Files

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

    Re: Every Combination of string from 4 columns

    That's 2.4 million combinations. What would you do if you had them all?
    Last edited by shg; 02-08-2017 at 08:56 AM.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,935

    Re: Every Combination of string from 4 columns

    Not sure the purpose either. But you'd need what's called Cartesian Product/Join.

    Easiest way to do it is to use PowerQuery (since you have Excel 2010).

    Convert each list to table. Load Segment 1 to PowerQuery.

    Add custom column with following M.
    Please Login or Register  to view this content.
    Where Name = Table name & [Segment 2] is the column name.

    Repeat for rest of the lists.

    Result should look like below.
    cartesian.JPG

    Expand each column. Convert data type to TEXT.

    Add Custom column and concatenate all columns.
    Please Login or Register  to view this content.
    Remove all but the concatenated column.

    Now you have the table.

    However, since it has more rows than can be loaded to a sheet, you will need to filter and split table into multiple and load.

  4. #4
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Every Combination of string from 4 columns

    try this code (from HansV from ElieensLounge forum)
    Please Login or Register  to view this content.
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  5. #5
    Forum Contributor
    Join Date
    08-02-2015
    Location
    Canada
    MS-Off Ver
    Office 2010
    Posts
    129

    Re: Every Combination of string from 4 columns

    We are looking to see how many account strings would be possible if we linked all the segments together. Just out of curiosity, how did you calculate to 2.4M? This is in itself is useful to us.

  6. #6
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,852

    Re: Every Combination of string from 4 columns

    Quote Originally Posted by leebird View Post
    ... Just out of curiosity, how did you calculate to 2.4M? ...
    Try this formula in cell F1:

    =(COUNTA(A:A)-1) * (COUNTA(B:B)-1) * (COUNTA(C:C)-1) * (COUNTA(D:D)-1)

    (the -1 is because you have headers in each column). The number of combinations is the product of the number of individual items in each column.

    Hope this helps.

    Pete

  7. #7
    Forum Contributor
    Join Date
    08-02-2015
    Location
    Canada
    MS-Off Ver
    Office 2010
    Posts
    129

    Re: Every Combination of string from 4 columns

    Excellent. Thank you so much. Appreciate all the help!

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

    Re: Every Combination of string from 4 columns

    Quote Originally Posted by leebird View Post
    ... how did you calculate to 2.4M? This is in itself is useful to us.
    It's the product of the number of entries in each column: =8*10*209*144

+ 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: 7
    Last Post: 10-05-2016, 08:05 PM
  2. [SOLVED] how to combination of three columns with Specified steps ?
    By wiliam_s in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-12-2016, 11:55 AM
  3. VBA Excel Combination of 2 Columns
    By beterman14 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-14-2015, 09:20 AM
  4. combination of letter to form new string
    By mqcai4613 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-15-2014, 10:11 AM
  5. [SOLVED] searchign for multple combination of string text
    By adamg6 in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 02-28-2013, 03:57 PM
  6. [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
  7. Generating combination of # into 2 columns:
    By Conrat in forum Excel General
    Replies: 2
    Last Post: 10-05-2011, 01:39 PM

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