How to extract only unique values from TEXTJOIN string?

Jasuan

New Member
Joined
Jan 16, 2014
Messages
34
Office Version
  1. 365
Platform
  1. Windows
Problem: Used textjoin to create tables based on an identifier. Textjoin has now created multiple stings of numbers (i.e. "7, 26" and "7, 37") and I can not figure out which function or combination of functions to use retain only the first unique instance of a number.

I have tried the following formula: =TEXTJOIN(", ",TRUE,IF(I2:I22<>"",IF(MATCH(I2:I22,I2:I22,0)=(ROW(I2:I22)-ROW(I1)),I2:I22,""),""))
However, this returns "7, 26, 7, 37, 7" When I only want "7, 26, 37"
1616915687016.png
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Are you using TEXTJOIN in Microsoft 365 or in Excel 2019?

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. (Don’t forget to scroll down & ‘Save’)
 
Upvote 0
Are you using TEXTJOIN in Microsoft 365 or in Excel 2019?

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. (Don’t forget to scroll down & ‘Save’)
I am using Microsoft 365
 
Upvote 0
Thanks for updating your profile. (y)

With 365 then you could try something like this

21 03 28.xlsm
IJ
1
27, 267, 26, 37
3
47, 37
57
6
Unique
Cell Formulas
RangeFormula
J2J2=TEXTJOIN(", ",1,UNIQUE(FILTERXML("<p><c>"&SUBSTITUTE(TEXTJOIN(", ",1,I2:I22),",","</c><c>")&"</c></p>","//c")))
 
Upvote 0
Thanks for updating your profile. (y)

With 365 then you could try something like this

21 03 28.xlsm
IJ
1
27, 267, 26, 37
3
47, 37
57
6
Unique
Cell Formulas
RangeFormula
J2J2=TEXTJOIN(", ",1,UNIQUE(FILTERXML("<p><c>"&SUBSTITUTE(TEXTJOIN(", ",1,I2:I22),",","</c><c>")&"</c></p>","//c")))
Hey Peter! This formula works great with one small exception: If a range has no values, like K2:K22, then it will return #VALUE! instead of just blank. I tried adding
Excel Formula:
=IF(I2:I22="","",TEXTJOIN(", ",1,UNIQUE(FILTERXML("<p><c>"&SUBSTITUTE(TEXTJOIN(", ",1,I2:I22),",","</c><c>")&"</c></p>","//c"))))
however, if the first cell in the range was blank, like J2, then it would produce no values.
 
Upvote 0
If a range has no values, like K2:K22, then it will return #VALUE! instead of just blank.
Excel Formula:
=TEXTJOIN(", ",1,UNIQUE(IFERROR(FILTERXML("<p><c>"&SUBSTITUTE(TEXTJOIN(", ",1,K2:K22),",","</c><c>")&"</c></p>","//c"),"")))
 
Upvote 0
Solution
Glad it worked for you. Thanks for the confirmation. :)
 
Upvote 0
Hey, the formula does work.

What about if i want the extracted values to be alphabetically ordered? :unsure:
 
Upvote 0
You can use the sort function, like
Excel Formula:
=TEXTJOIN(", ",1,SORT(UNIQUE(FILTERXML("<p><c>"&SUBSTITUTE(TEXTJOIN(", ",1,I2:I22),",","</c><c>")&"</c></p>","//c"))))
 
Upvote 0

Forum statistics

Threads
1,215,412
Messages
6,124,761
Members
449,187
Latest member
hermansoa

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