r/excel • • 22d ago

unsolved I need to unify rows with duplicate data while keeping all different values

Hi everyone, in order to explain better I'll just make an example.

I have something like this:

IDTopic
001apple
001banana
002apple
003cherry
003avocado
004cherry
004apple
004banana

And I need to automatically transform it into something like this:

IDTopic1Topic2Topic3
001applebanana
002apple
003cherryavocado
004cherryapplebanana

In the actual file, I have thousands of rows and a lot of columns. In the file, I have multiple columns where the data is the same, while other information is different, and I need to have a unique row for each ID.

My experience with Excel is above average, but definitely not high, and I'm stuck on this passage.

Do you have any suggestions?

Thanks in advance!

11 Upvotes

18 comments sorted by

•

u/AutoModerator 22d ago

/u/InvisibleJune - Your post was submitted successfully.

Failing to follow these steps may result in your post being removed without warning.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

7

u/RuktX 313 22d ago

Does your experience extend to Power Query? This would be a fairly straightforward Group > Text.Combine > Split Column.

2

u/InvisibleJune 21d ago

I never used it, but I can always learn ahah

1

u/MoltoBeneGesserit 22d ago

Yeah this is a good call. Had to use power query like this for work and this should do the trick.

4

u/MayukhBhattacharya 1327 22d ago

Try using the following formula:

=LET(
     _a, A:.B,
     _b, INDEX(_a, , 1),
     _c, MAP(_b, LAMBDA(x, COUNTIF(INDEX(_b, 1):x, x))),
     _d, PIVOTBY(_b,
                 TAKE(_a, 1, -1) & " " & _c,
                 CHOOSECOLS(_a, 2),
                 SINGLE, 1, 0, , 0),
     IFNA(EXPAND("ID\Topic", 2, 2), _d))

Or, same formula without using the MAP()

=LET(
     _a, A:.B,
     _b, INDEX(_a, , 1),
     _c, SEQUENCE(ROWS(_b), , 2) - XMATCH(_b, _b),
     _d, PIVOTBY(_b,
                 TAKE(_a, 1, -1) & " " & _c,
                 CHOOSECOLS(_a, 2),
                 SINGLE, 1, 0, , 0),
     IFNA(EXPAND("ID\Topic", 2, 2), _d))

3

u/Akanaton 22d ago

I think you could do this in a tabular pivot table without subtotals or the Harray/horizontal array formula

3

u/Way2trivial 475 22d ago

h5

=UNIQUE(C5:C12)

i5, copied down to the end

=TRANSPOSE(FILTER(D5:D12,C5:C12=H5))

Edit- forgot the absolute references
=TRANSPOSE(FILTER(D$5:D$12,C$5:C$12=H5))

2

u/Decronym 22d ago edited 19d ago

Acronyms, initialisms, abbreviations, contractions, and other phrases which expand to something larger, that I've seen in this thread:

Fewer LettersMore Letters
CHOOSECOLSOffice 365+: Returns the specified columns from an array
COUNTACounts how many values are in the list of arguments
COUNTIFCounts the number of cells within a range that meet the given criteria
DROPOffice 365+: Excludes a specified number of rows or columns from the start or end of an array
EXPANDOffice 365+: Expands or pads an array to specified row and column dimensions
FILTEROffice 365+: Filters a range of data based on criteria you define
GROUPBYHelps a user group, aggregate, sort, and filter data based on the fields you specify
HSTACKOffice 365+: Appends arrays horizontally and in sequence to return a larger array
IFSpecifies a logical test to perform
IFERRORReturns a value you specify if a formula evaluates to an error; otherwise, returns the result of the formula
IFNAExcel 2013+: Returns the value you specify if the expression resolves to #N/A, otherwise returns the result of the expression
INDEXUses an index to choose a value from a reference or array
LAMBDAOffice 365+: Use a LAMBDA function to create custom, reusable functions and call them by a friendly name.
LETOffice 365+: Assigns names to calculation results to allow storing intermediate calculations, values, or defining names inside a formula
MAKEARRAYOffice 365+: Returns a calculated array of a specified row and column size, by applying a LAMBDA
MAPOffice 365+: Returns an array formed by mapping each value in the array(s) to a new value by applying a LAMBDA to create a new value.
MAXReturns the maximum value in a list of arguments
PIVOTBYHelps a user group, aggregate, sort, and filter data based on the row and column fields that you specify
ROWSReturns the number of rows in a reference
SCANOffice 365+: Scans an array by applying a LAMBDA to each value and returns an array that has each intermediate value.
SEQUENCEOffice 365+: Generates a list of sequential numbers in an array, such as 1, 2, 3, 4
TAKEOffice 365+: Returns a specified number of contiguous rows or columns from the start or end of an array
TRANSPOSEReturns the transpose of an array
Text.CombinePower Query M: Returns a text value that is the result of joining all text values with each value separated by a separator.
UNIQUEOffice 365+: Returns a list of unique values in a list or range
VSTACKOffice 365+: Appends arrays vertically and in sequence to return a larger array
XMATCHOffice 365+: Returns the relative position of an item in an array or range of cells.

Decronym is now also available on Lemmy! Requests for support and new installations should be directed to the Contact address below.


Beep-boop, I am a helper bot. Please do not verify me as a solution.
27 acronyms in this thread; the most compressed thread commented on today has 15 acronyms.
[Thread #49665 for this sub, first seen 11th Nov 2026, 15:08] [FAQ] [Full list] ^[Contact] [Source code]

1

u/Downtown-Economics26 647 21d ago
=LET(gb,GROUPBY(DROP(A:.A,1),DROP(A:.A,1),COUNTA,,0),
grid,MAKEARRAY(ROWS(gb),MAX(INDEX(gb,,2)),LAMBDA(r,c,
IFERROR(INDEX(FILTER(B:.B,A:.A=INDEX(gb,r,1),""),c),""))),
headers,HSTACK("ID","Topic"&SEQUENCE(,MAX(INDEX(gb,,2)))),
out,VSTACK(headers,HSTACK(INDEX(gb,,1),grid)),
out)

1

u/Clearwings_Prime 25 21d ago

=PIVOTBY( A2:A9,"Topic " & SCAN(0, A2:A9<>A1:A8,LAMBDA(b,c, IF(c,1,b+1))), B2:B9,SINGLE,0,0,,0)

1

u/carbonizedtitanium 2 19d ago

on your second sheet:

A2: =Unique(Filter(Sheet1!A2:A10000, Sheet1!A2:A10000>0))

B2: =Transpose(Filter(Sheet1!$B$2:$B$10000, A2=Sheet1!$A$2:$A$10000)) drag formula down

0

u/ShittyAnimorph 21d ago

Buncha tryhards trying to solve it in a single formula... (I kid)

Here's what I'd do: Sort by id, then by topic. The below assumes row 1 is headers. Put it in c2 and carry down.

=If(a2<>a1, b2, if(b2=b3,c3,c3&","&b2,c3))

Open a new sheet and paste in your ID column then remove duplicates. Then do

=Textsplit(vlookup(a2,originalsheet!a:c,3,false),",")

Then copy paste that whole sheet as values and you're done.

0

u/[deleted] 21d ago

[removed] — view removed comment

1

u/InvisibleJune 20d ago

Hi, thank you! I have never used Power Query before, so I'm trying to understand how to do this (or any of the suggested things from other commenters). I managed easily to arrive until the second point, but I have no idea how to do the third one (Keep ID and the indexed table column; expand Topic and the index. Pivot the index column using Topic as the values and Don't aggregate). I am looking for tutorials online to see what I'm missing, but in the end I can't find how to do it. Would you be able to explain it to me or do you have any external source I could use for this?

0

u/[deleted] 19d ago edited 19d ago

[removed] — view removed comment

1

u/AutoModerator 19d ago

I have detected code containing Fancy/Smart Quotes which Excel does not recognize as a string delimiter. Edit to change those to regular quote-marks instead. This happens most often with mobile devices. You can turn off Fancy/Smart Punctuation in the settings of your Keyboard App.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.