Need a formula or Query to list out unique values

signup

New Member
Joined
Feb 15, 2018
Messages
42
Office Version
  1. 2019
Platform
  1. Windows
I have a sheet similar to the below data. Can we list out the unique names for each location? as shown in the below "desired output" section?


LocationNames
Location 1Name 1, Name 2, Name 4
Location 1Name 1, Name 4
Location 1Name 2, Name 3, Name 5
Location 1Name 1
Location 1Name 2
Location 1Name 6
Location 2Name 7, Name 1, Name 8
Location 2Name 2, Name 1
Location 2Name 2
Location 2Name 2, Name 9
Location 2Name 10
Location 3Name 11, Name 12, Name 1
Location 3Name 13
Location 3Name 1
Location 3Name 11
Location 3Name 1, Name 14

Desired Output:

LocationNames
Location 1Name 1, Name 2, Name 3, Name 4, Name 5, Name 6
Location 2Name 1, Name 2, Name 7, Name 8, Name 9, Name 10
Location 3Name 1, Name 11, Name 12, Name 13, Name 14

Thanks in advance!
 
In that case check that you don't have any leading/trailing spaces in the Location cells. Also the code is case sensitive, but that can be changed very easily if needed.
 
Upvote 0

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Have you tried to replicate the Power Query Solution. Further info on this Excel function if you are not aware.

Power Query is a free AddIn for Excel 2010 and 2013, and is built-in functionality from Excel 2016 onwards (where it is referred to as "Get & Transform Data").

It is a powerful yet simple way of getting, changing and using data from a broad variety of sources, creating steps which may be easily repeated and refreshed. I strongly recommend learning how to use Power Query - it's among the most powerful functionalities of Excel.

- Follow this link to learn how to install Power Query in Excel 2010 / 2013.

- Follow this link for an introduction to Power Query functionality.

- Follow this link for a video which demonstrates how to use Power Query code provided.
 
Upvote 0
An alternative solution is to use Power Query to find the unique items. Mcode follows.

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Changed Type", "Column2", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"Column2.1", "Column2.2", "Column2.3"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Column2.1", type text}, {"Column2.2", type text}, {"Column2.3", type text}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type1", {"Column1"}, "Attribute", "Value"),
    #"Trimmed Text" = Table.TransformColumns(#"Unpivoted Other Columns",{{"Value", Text.Trim, type text}}),
    #"Removed Columns" = Table.RemoveColumns(#"Trimmed Text",{"Attribute"}),
    #"Removed Duplicates" = Table.Distinct(#"Removed Columns")
in
    #"Removed Duplicates"

Then bring the query into power pivot and create a new measure


and then the final result

Book5
AB
1Column1New Value
2Location 1Name 1, Name 2, Name 4, Name 3, Name 5, Name 6
3Location 2Name 7, Name 1, Name 8, Name 2, Name 9, Name 10
4Location 3Name 11, Name 12, Name 1, Name 13, Name 14
Table1
First of all my sincere apologies for the late reply. Due to personal commitments, I couldn't reply back early. @Fluff @alansidman

Thanks for providing the power query, I'm new to use these things like Power Query and Macros. Whenever I feel the required output can be done in another way(By saving the hours of manual time) then I'm requesting in the forum. I just know how to apply the power query on a table of data. So, I'm unable to do the second step(create a new measure) u have mentioned in the post.

Can you please help me with that? Thanks once again for taking the time and providing the help.
 
Upvote 0
No VBA. Three steps, the best one was modified from stuff I found on stackexchange. textjoin based on location; the stakeexchange part turns that long string into a new array, then unique the array and join it back together.
:
MrExcelPlayground.xlsm
LMNOPQR
3LocationNames
4Location 1Name 1, Name 2, Name 4
5Location 1Name 1, Name 4
6Location 1Name 2, Name 3, Name 5
7Location 1Name 1
8Location 1Name 2LocationConcatenateduniquesAll in one formula
9Location 1Name 6Location 1Name 1, Name 2, Name 4, Name 1, Name 4, Name 2, Name 3, Name 5, Name 1, Name 2, Name 6Name 1, Name 2, Name 4, Name 3, Name 5, Name 6Name 1, Name 2, Name 4, Name 3, Name 5, Name 6
10Location 2Name 7, Name 1, Name 8Location 2Name 7, Name 1, Name 8, Name 2, Name 1, Name 2, Name 2, Name 9, Name 10Name 7, Name 1, Name 8, Name 2, Name 9, Name 10Name 7, Name 1, Name 8, Name 2, Name 9, Name 10
11Location 2Name 2, Name 1Location 3Name 11, Name 12, Name 1, Name 13, Name 1, Name 11, Name 1, Name 14Name 11, Name 12, Name 1, Name 13, Name 14Name 11, Name 12, Name 1, Name 13, Name 14
12Location 2Name 2
13Location 2Name 2, Name 9
14Location 2Name 10
15Location 3Name 11, Name 12, Name 1
16Location 3Name 13
17Location 3Name 1
18Location 3Name 11
19Location 3Name 1, Name 14
Sheet22
Cell Formulas
RangeFormula
P9:P11P9=TEXTJOIN(", ",TRUE,IF($L$4:$L$19=O9,$M$4:$M$19,""))
Q9:Q11Q9=TEXTJOIN(", ",TRUE,UNIQUE(TRIM(MID(SUBSTITUTE(P9,", ",REPT(" ",99)),IF(SEQUENCE(LEN(P9)-LEN(SUBSTITUTE(P9,", ",""))+1)=1,1,(SEQUENCE(LEN(P9)-LEN(SUBSTITUTE(P9,", ",""))+1)-1)*99),99))))
R9:R11R9=TEXTJOIN(", ",TRUE,UNIQUE(TRIM(MID(SUBSTITUTE(TEXTJOIN(", ",TRUE,IF($L$4:$L$19=O9,$M$4:$M$19,"")),", ",REPT(" ",99)),IF(SEQUENCE(LEN(TEXTJOIN(", ",TRUE,IF($L$4:$L$19=O9,$M$4:$M$19,"")))-LEN(SUBSTITUTE(TEXTJOIN(", ",TRUE,IF($L$4:$L$19=O9,$M$4:$M$19,"")),", ",""))+1)=1,1,(SEQUENCE(LEN(TEXTJOIN(", ",TRUE,IF($L$4:$L$19=O9,$M$4:$M$19,"")))-LEN(SUBSTITUTE(TEXTJOIN(", ",TRUE,IF($L$4:$L$19=O9,$M$4:$M$19,"")),", ",""))+1)-1)*99),99))))


The "R" column has it all in one nasty formula.
Hey, My sincere apologies for the late reply.

I'm a newbie so it looks a bit confusing to use this on my sheet. Earlier one or two times I have used Power query. So, I would like to have a solution on the same. Thanks once again for taking the time and providing the solution.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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