get unique items from an array (not a range)

Riesenrind

New Member
Joined
Sep 18, 2012
Messages
13
Office Version
  1. 365
Platform
  1. Windows
I have an excel formula which is collecting data from various sources and putting it into a JSON-style array, e.g. ["apple","banana","banana","orange"] in B2
I want to write another formula which will exclude the duplicates, i.e. return ["apple","banana","orange"].

I have tried converting this to UNIQUE(B2) ... no luck
tried UNIQUE(SUBSTITUTE(SUBSTITUTE(B2,"[","{")"]","}") ... no luck
tried addiitonally subsituting UNIQUE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(B2,"[","{")"]","}",";",",") .... also no luck

Is there any way to do this?
I'm using Excel 365. Because I have a lot of data I would prefer to avoid using VBA or volatile formula
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Until textsplit comes, use this:
MrExcelPlayground12.xlsx
AB
8"Apple","Banana","Banana","Orange""Apple","Banana","Orange"
Sheet12
Cell Formulas
RangeFormula
B8B8=TEXTJOIN(",",TRUE,UNIQUE(FILTERXML("<a><s>" &SUBSTITUTE(A8,",","</s><s>") & "</s></a>","//s")))
 
Upvote 0
Hey @JamesCanale
Thank you very much for the quick answer. It works well with my example, but not if the last two items are the same
e.g. ["apple","banana","banana","orange"] returns ["apple","banana","banana"]
 
Upvote 0
I'm using Excel 365
I suggest that you update your Account details (or 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’)

Another option
Excel Formula:
="["&TEXTJOIN(",",,UNIQUE(TEXTSPLIT(B2,{"[",",","]"},,1),1))&"]"
 
Upvote 0
@JamesCanale
I have extended your solution
=TEXTJOIN(",",TRUE,UNIQUE(FILTERXML("<a><s>" &SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A9,"[","[<s>"),"]","</s>]"),",","</s><s>") & "</s></a>","//s")))
but it is still not quite working. It returns: [],"apple","banana"
 
Upvote 0
The brackets were problematic. I removed them and reinstall:
MrExcelPlayground12.xlsx
AB
8["Apple","Orange","Banana","Banana"]["Apple","Orange","Banana"]
Sheet12
Cell Formulas
RangeFormula
B8B8="["&TEXTJOIN(",",TRUE,UNIQUE(FILTERXML("<a><s>" &SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A8,"[",""),"]",""),",","</s><s>") & "</s></a>","//s")))&"]"
 
Upvote 0
@JamesCanale Your last proposal worked perfectly. Thank you very much!
@Fluff My version of Excel isnt supporting TEXTSPLIT. But thank you anyway. I took your hint an updated my account into
 
Upvote 0

Forum statistics

Threads
1,214,784
Messages
6,121,535
Members
449,037
Latest member
tmmotairi

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