Find unique values and then concatenate

nikhil0311

Board Regular
Joined
May 3, 2013
Messages
200
Office Version
  1. 2013
Platform
  1. Windows
We have different countries available in column A
In Column B & C from row 3 we have the raw data
in cell B2 & C2 we have the final output
What I am looking for is
1 - In column B from B3:B12 find unique values
2 - concatenate the unique values with the countries present in column A (please refer output 1 & 2)


Output 1Output 2
CountriesYes:AUNZ;MY;SG
No:CN;IN;PH;TH
Complete : AUNZ CN IN MY
30 Day Activity : KR
No: PH
Not needed: TH
AUNZYesComplete
CNNoComplete
INNoComplete
KR30 Day Activity
MYYesComplete
PHNoNo
SGYes
TW
THNoNot needed
VN
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Hi,
What version of excel are you using?
If 365.

mrxcel2020.xlsx
ABCD
3CountriesOutput 1Output 2
4AUNZYesComplete
5CNNoComplete
6INNoComplete
7KR30 Day Activity
8MYYesComplete
9PHNoNo
10SGYes
11TW
12THNoNot needed
13VN
14
15Output 1Output 2
16YesAUNZ,MY,SGcompleteAUNZ,CN,IN,MY
17NoCN,IN,PH,TH30 Day ActivityKR
18KR,TW,VNNoPH
19Not neededTH
20SG,TW,VN
nikhil0311
Cell Formulas
RangeFormula
B16:B18B16=TEXTJOIN(",",TRUE,IF(Raw_data[Output 1]=A16,Raw_data[Countries],""))
D16:D20D16=TEXTJOIN(",",TRUE,IF(Raw_data[Output 2]=C16,Raw_data[Countries],""))
 
Upvote 0
If by "generate unique values" you mean to extract from the raw data, try as follows:

mrxcel2020.xlsx
ABCD
3CountriesOutput 1Output 2
4AUNZYesComplete
5CNNoComplete
6INNoComplete
7KR30 Day Activity
8MYYesComplete
9PHNoNo
10SGYes
11TW
12THNoNot needed
13VN
14
15Output 1concatenated 1Output 2concatenated 2
160KR,TW,VN0SG,TW,VN
17NoCN,IN,PH,THNot neededTH
18YesAUNZ,MY,SGNoPH
19 CompleteAUNZ,CN,IN,MY
2030 Day ActivityKR
21 
nikhil0311
Cell Formulas
RangeFormula
B16:B18B16=TEXTJOIN(",",TRUE,IF(Raw_data[Output 1]=A16,Raw_data[Countries],""))
A16:A19A16=IFERROR(LOOKUP(2,1/(COUNTIF($A$15:A15,Raw_data[Output 1])=0),Raw_data[Output 1]),"")
D16:D20D16=TEXTJOIN(",",TRUE,IF(Raw_data[Output 2]=C16,Raw_data[Countries],""))
C16:C21C16=IFERROR(LOOKUP(2,1/(COUNTIF($C$15:C15,Raw_data[Output 2])=0),Raw_data[Output 2]),"")
 
Upvote 0
Firstly, I suggest that you update your Account details (click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version.

FORMULAS
If you are looking for a formula approach & you have Excel 365 with the new dynamic array functions (UNIQUE & FILTER in this case) you could try this using helper cells.

Formula is entered in B15 only. Other unique values from column B will automatically 'spill' down to cells below.
Same for formula in D15
Formulas in C15 and E15 are copied down as far as you might ever need. (I have copied to row 20)
Formulas in B2 & C2 are stand-alone. These cells will need to have 'Wrap Text' set.

nikhil0311 2020-03-06 1.xlsm
ABCDE
2Yes:AUNZ;MY;SG No:CN;IN;PH;THComplete:AUNZ;CN;IN;MY 30 Day Activity:KR No:PH Not needed:TH
3AUNZYesComplete
4CNNoComplete
5INNoComplete
6KR30 Day Activity
7MYYesComplete
8PHNoNo
9SGYes
10TW
11THNoNot needed
12VN
13
14
15YesYes:AUNZ;MY;SGCompleteComplete:AUNZ;CN;IN;MY
16NoNo:CN;IN;PH;TH30 Day Activity30 Day Activity:KR
17 NoNo:PH
18 Not neededNot needed:TH
19  
20  
21
Formulas
Cell Formulas
RangeFormula
B2B2=TEXTJOIN(CHAR(10),1,C15:C20)
C2C2=TEXTJOIN(CHAR(10),1,E15:E20)
B15:B16B15=UNIQUE(FILTER(B3:B12,B3:B12<>""))
D15:D18D15=UNIQUE(FILTER(C3:C12,C3:C12<>""))
C15:C20C15=IF(B15="","",B15&":"&TEXTJOIN(";",1,FILTER(A$3:A$12,B$3:B$12=B15)))
E15:E20E15=IF(D15="","",D15&":"&TEXTJOIN(";",1,FILTER(A$3:A$12,C$3:C$12=D15)))
Dynamic array formulas.



VBA
If you are looking for a vba approach then you could try this user-defined function with no need for helper cells.
To implement ..
1. Right click the sheet name tab and choose "View Code".
2. In the Visual Basic window use the menu to Insert|Module
3. Copy and Paste the code below (use the icon at the top right of the code pane) into the main right hand pane that opens at step 2.
4. Close the Visual Basic window.
5. Enter the B2 formula as shown in the screen shot below and copy across to C2. Again B2:C2 need 'Wrap Text'

VBA Code:
Function Countries(rUnique As Range, rCountries As Range) As String
  Dim aU As Variant, aC As Variant, Ky As Variant
  Dim d As Object
  Dim i As Long
  
  Set d = CreateObject("Scripting.Dictionary")
  d.CompareMode = 1
  aU = rUnique.Value
  aC = rCountries.Value
  For i = 1 To UBound(aU)
    If Len(aU(i, 1)) Then
      d(aU(i, 1)) = d(aU(i, 1)) & ";" & aC(i, 1)
    End If
  Next i
  For Each Ky In d.keys
    Countries = Countries & vbLf & Ky & ":" & Mid(d(Ky), 2)
  Next Ky
  Countries = Mid(Countries, 2)
End Function

nikhil0311 2020-03-06 1.xlsm
ABC
2Yes:AUNZ;MY;SG No:CN;IN;PH;THComplete:AUNZ;CN;IN;MY 30 Day Activity:KR No:PH Not needed:TH
3AUNZYesComplete
4CNNoComplete
5INNoComplete
6KR30 Day Activity
7MYYesComplete
8PHNoNo
9SGYes
10TW
11THNoNot needed
12VN
13
vba
Cell Formulas
RangeFormula
B2:C2B2=Countries(B3:B12,$A3:$A12)
 
Upvote 0
i am using excel 2013
Then I would suggest the vba approach.


I would also still suggest ..
.. that you update your Account details (click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version.
 
Upvote 0

Forum statistics

Threads
1,223,981
Messages
6,175,768
Members
452,668
Latest member
mrider123

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