Combine Cells when same Value in another column

Dani_LobP

Board Regular
Joined
Aug 16, 2019
Messages
134
Office Version
  1. 365
Platform
  1. Windows
Hi,

I'm struggling to find a way to make some textjoin alike formula with IF condition and also "unique" too in order to combine results that share same value.

I have something as per below example:

IDType
Name1Type1
Name1Type2
Name2Type2
Name3Type1
Name4Type1
Name4Type1
Name4Type1

And the result I would like to obtain, is to display for each Name, what combinations they have..

Name1 should display Type1-Type2
Name2 should display Type2
Name3 should display Type1
Name4 should display Type1-Type1

Excel Formula:
=TEXTJOIN("-",TRUE,SORT(UNIQUE(IF([ID]=[@[ID]],[Type],""))))

Ofc if using Unique, it wont allow repetition as Type1-Type1 for example, but unsure of how other option i can do so it allows at least 1 duplication...

Hope it makes sense the explanation and the goal.

thanks in advance!
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
how about
=TEXTJOIN(",",,SORT(UNIQUE(FILTER($B$2:$B$8,$A$2:$A$8=D2))))
Book6
ABCDE
1IDTypeID
2Name1Type1Name1Type1,Type2
3Name1Type2Name2Type2
4Name2Type2Name3Type1
5Name3Type1Name4Type1
6Name4Type10
7Name4Type1
8Name4Type1
Sheet1
Cell Formulas
RangeFormula
D1:D6D1=UNIQUE(A:A)
E2:E5E2=TEXTJOIN(",",,SORT(UNIQUE(FILTER($B$2:$B$8,$A$2:$A$8=D2))))
Dynamic array formulas.
 
Upvote 0
how about
=TEXTJOIN(",",,SORT(UNIQUE(FILTER($B$2:$B$8,$A$2:$A$8=D2))))
Book6
ABCDE
1IDTypeID
2Name1Type1Name1Type1,Type2
3Name1Type2Name2Type2
4Name2Type2Name3Type1
5Name3Type1Name4Type1
6Name4Type10
7Name4Type1
8Name4Type1
Sheet1
Cell Formulas
RangeFormula
D1:D6D1=UNIQUE(A:A)
E2:E5E2=TEXTJOIN(",",,SORT(UNIQUE(FILTER($B$2:$B$8,$A$2:$A$8=D2))))
Dynamic array formulas.

Thanks, this works partially, since i believe it makes same result i obtain, those cases with Type1-Type1, will appear just as type1... and somehow i need to display Type1-Type1 ... but not type1-type1-type1 ... if that makes sense :)
in some way i want "uniques" up to 2 times duplicated... not sure if its actually possible.
 
Upvote 0
Thanks, this works partially, since i believe it makes same result i obtain, those cases with Type1-Type1, will appear just as type1... and somehow i need to display Type1-Type1 ... but not type1-type1-type1 ... if that makes sense :)
in some way i want "uniques" up to 2 times duplicated... not sure if its actually possible.

Hello, I have a question concerning the data - is it possible that for some names there are several types, e.g. type 1 - type 1 - type 1 - type - 2 - type 2? I.e. the expected outcome would be type 1 - type 1 - type 2 - type 2?
 
Upvote 0
not sure how to do that , i will have a look into - hopefully another member may have a solution
 
Upvote 0
Hello, I have a question concerning the data - is it possible that for some names there are several types, e.g. type 1 - type 1 - type 1 - type - 2 - type 2? I.e. the expected outcome would be type 1 - type 1 - type 2 - type 2?

Yes, it can happen.
the Type is actually connected to the name of a person, so type1-Type1 means that 2 different persons checked Name1. So type1-Type1-type2-type2 would mean that 4 different persons checked the Name, and they are split in 2 and 2 types ... if that makes sense.
 
Upvote 0
not sure i follow - can you give the example
type1 appears 3 times for name 4
so you want that twice
 
Upvote 0
How about
Fluff.xlsm
ABCDE
1IDType
2Name1Type1Name1Type1-Type2
3Name1Type2Name2Type2
4Name2Type2Name3Type1
5Name3Type1Name4Type1-Type1-Type2
6Name4Type1
7Name4Type2
8Name4Type1
Data
Cell Formulas
RangeFormula
D2:D5D2=UNIQUE(TOCOL(A2:A100,1))
E2:E5E2=LET(f,FILTER($B$2:$B$100,$A$2:$A$100=D2),r,ROWS(f),TEXTJOIN("-",,SORT(FILTER(f,MMULT((SEQUENCE(r)>=SEQUENCE(,r))*(f=TOROW(f)),SEQUENCE(r,,,0))<=2))))
Dynamic array formulas.
 
Upvote 1
Solution
Here is another option (but Fluff's solution is definitely more elegant):

Excel Formula:
=LET(
array,SORT(FILTER($B$2:$B$8,$A$2:$A$8=D2)),
count,CHOOSECOLS(HSTACK(UNIQUE(array),MAP(UNIQUE(array),LAMBDA(x,SUM(--(array=x))))),2),
sequence,DROP(REDUCE("",count,LAMBDA(a,b,VSTACK(a,SEQUENCE(b)))),1),
TEXTJOIN("-",,FILTER(array,sequence<=2)))
 
Upvote 0
How about
Fluff.xlsm
ABCDE
1IDType
2Name1Type1Name1Type1-Type2
3Name1Type2Name2Type2
4Name2Type2Name3Type1
5Name3Type1Name4Type1-Type1-Type2
6Name4Type1
7Name4Type2
8Name4Type1
Data
Cell Formulas
RangeFormula
D2:D5D2=UNIQUE(TOCOL(A2:A100,1))
E2:E5E2=LET(f,FILTER($B$2:$B$100,$A$2:$A$100=D2),r,ROWS(f),TEXTJOIN("-",,SORT(FILTER(f,MMULT((SEQUENCE(r)>=SEQUENCE(,r))*(f=TOROW(f)),SEQUENCE(r,,,0))<=2))))
Dynamic array formulas.
thanks, that's somehow what I was trying to find. I had to edit a bit the data after spotting some weird results but now works perfect. thanks!
 
Upvote 0

Forum statistics

Threads
1,224,812
Messages
6,181,099
Members
453,021
Latest member
Justyna P

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