+ Reply to Thread
Results 1 to 6 of 6

Combining Values in Multiple Rows into 1 Row of Comma-Separated Values Based on Duplicates

  1. #1
    Registered User
    Join Date
    07-25-2018
    Location
    Hattiesburg, MS
    MS-Off Ver
    365 ProPlus
    Posts
    5

    Combining Values in Multiple Rows into 1 Row of Comma-Separated Values Based on Duplicates

    Hello All,

    I have an Excel workbook that contains Supplier ID numbers and Building Reference numbers. One Supplier ID may be listed in multiple rows, and have a unique Building Reference listed next to each entry. I want to combine multiple entries of a distinct Supplier ID into 1 row, and combine the Building Reference numbers into one cell in each row, separated by commas. I have provided an example below, and have attached an Excel workbook in case formatting is an issue. There are 2 separate example sheets for the data I have, and the output I'd like to see.

    The Data I Have
    A B
    Supplier ID Building Reference
    100 A
    100 B
    100 C
    250 A
    250 Z
    600 C
    600 G
    600 H
    600 J

    The Format I Want
    A B
    Supplier ID Building Reference
    100 A,B,C
    250 A,Z
    600 C,G,H,J

    If the combined, comma-separated Building References end up being listed on every row of the original sheet, so be it. I can delete duplicate rows afterward.
    Any help will be greatly appreciated!
    Attached Files Attached Files

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

    Re: Combining Values in Multiple Rows into 1 Row of Comma-Separated Values Based on Duplic

    Use column C in your source sheet as a helper column, with this formula in C2:

    =IF(A2="","",IF(COUNTIF(A$2:A2,A2)=1,INT(MAX(C$1:C1)/1000)*1000+1000,C1+1))

    Copy this down as far as you need it. It will identify each supplier with a number in the thousands, and then identify each Building Reference with a unique sequential number, so that you get 1000, 1001, 1002, 2000, 2001, and so on.

    Then in A2 of the second sheet you can have this formula:

    =IFERROR(INDEX('The Data I Have'!A:A,MATCH(ROWS('The Data I Have'!$1:1)*1000,'The Data I Have'!C:C,0)),"")

    which will return a unique list of Supplier IDs when copied down. In B2 of that sheet you can have this formula:

    =IF(A2="","",SUBSTITUTE(IFERROR(INDEX('The Data I Have'!B:B,MATCH(ROWS('The Data I Have'!$1:1)*1000,'The Data I Have'!C:C,0))&", ","")&IFERROR(INDEX('The Data I Have'!B:B,MATCH(ROWS('The Data I Have'!$1:1)*1000+1,'The Data I Have'!C:C,0))&", ","")&IFERROR(INDEX('The Data I Have'!B:B,MATCH(ROWS('The Data I Have'!$1:1)*1000+2,'The Data I Have'!C:C,0))&", ","")&IFERROR(INDEX('The Data I Have'!B:B,MATCH(ROWS('The Data I Have'!$1:1)*1000+3,'The Data I Have'!C:C,0))&", ","")&"zzz",", zzz",""))

    which might be easier to follow if I put manual line breaks in it, like this:

    =IF(A2="","",SUBSTITUTE(
    IFERROR(INDEX('The Data I Have'!B:B,MATCH(ROWS('The Data I Have'!$1:1)*1000,'The Data I Have'!C:C,0))&", ","")&
    IFERROR(INDEX('The Data I Have'!B:B,MATCH(ROWS('The Data I Have'!$1:1)*1000+1,'The Data I Have'!C:C,0))&", ","")&
    IFERROR(INDEX('The Data I Have'!B:B,MATCH(ROWS('The Data I Have'!$1:1)*1000+2,'The Data I Have'!C:C,0))&", ","")&
    IFERROR(INDEX('The Data I Have'!B:B,MATCH(ROWS('The Data I Have'!$1:1)*1000+3,'The Data I Have'!C:C,0))&", ","")&
    "zzz",", zzz",""))

    This will bring up to 4 Building Refs (separated by comma and space) across for each supplier, but hopefully you can see how it can be extended if your real data has more. Again, copy this down as far as you need to. The "zzz" and SUBSTITUTE function gets rid of the final comma-space in any group.

    Hope this helps.

    Pete

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: Combining Values in Multiple Rows into 1 Row of Comma-Separated Values Based on Duplic

    Hi gibsolj1,

    Your problem can be done using Power Query. See the attached where I have done the steps.

    PQ Group and Extract list delimited.xlsx

    I got my answer from this YouTube example. https://www.youtube.com/watch?v=Z0bNsVLfmac&t=249s
    (I actually sent your problem to OZ and he showed me how to do it.)
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Forum Contributor
    Join Date
    12-16-2011
    Location
    Portland, OR
    MS-Off Ver
    Excel 2016 Preview
    Posts
    105

    Re: Combining Values in Multiple Rows into 1 Row of Comma-Separated Values Based on Duplic

    MarvP, thanks for sharing.

    This is the video that shows the Table.Column solution in order to get the data grouped together: Redux: Students, Courses, Power Query ...

  5. #5
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: Combining Values in Multiple Rows into 1 Row of Comma-Separated Values Based on Duplic

    OK,

    After a few trials and errors using M Language Table.functions, I finally understand Table.Column(TableName,ColumnName). I hope gibsoljl has a version of Excel that does Power Query.

  6. #6
    Registered User
    Join Date
    07-25-2018
    Location
    Hattiesburg, MS
    MS-Off Ver
    365 ProPlus
    Posts
    5

    Re: Combining Values in Multiple Rows into 1 Row of Comma-Separated Values Based on Duplic

    Thanks, everyone, for your input. I just now had a chance to get back to this. I will look through responses and report back! Thank you.

+ 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: 4
    Last Post: 11-16-2015, 05:12 AM
  2. [SOLVED] Insert row based on a list of comma-separated values in one related cell
    By AEPS in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-31-2014, 10:35 AM
  3. Comma Separated values in Rows and columns
    By abhijeet_gole in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-10-2013, 12:45 AM
  4. Replies: 1
    Last Post: 11-10-2011, 12:57 PM
  5. Return Y/N after matching from multiple lookup values separated by comma
    By indoglans in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-16-2011, 03:13 PM
  6. Best way to parse colums and rows w/ multiple values separated by comma?
    By Sutukh19 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-28-2009, 04:37 AM
  7. Transpose multiple comma separated values
    By SRd240sx in forum Excel General
    Replies: 2
    Last Post: 12-07-2009, 09:36 PM

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