Remove duplicate values in cells using Power Query

programsam

Board Regular
Joined
Feb 10, 2016
Messages
123
Greetings,

I'm not looking to remove duplicates in a column but when joining tables, I have some where multiples of the same values are concatenated in a single cell. Example:

1690555925247.png


I Want for the first row to read Tom, Sam and omit the second (and any additional) instances of "Sam". How would this be achieved?
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Maybe:

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
    #"Split Column by Delimiter" = Table.SplitColumn(Source, "Column1", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"Column1.1", "Column1.2", "Column1.3"}),
    #"Merged Columns" = Table.CombineColumns(#"Split Column by Delimiter",{"Column1.1", "Column1.2"},Combiner.CombineTextByDelimiter(",", QuoteStyle.None),"Merged"),
    #"Removed Columns" = Table.RemoveColumns(#"Merged Columns",{"Column1.3"})
in
    #"Removed Columns"
 
Upvote 0
Try the following. Comments would help to see what's going on.
Change the source with the actual source since it is using binary sample data.

Power Query:
let
    // I used a binary data sample. You need to change this with your own source. This is only for testing the code quickly.
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCsnP1VEIToQQSrE6YBEwDeODJcGCsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Names = _t]),
    // Add a new column creating a list from the names split by usung the Text.Split() function
    // Then simply use the List.Disctinct() function to remove the duplicates from the list
    AddColumn = Table.AddColumn(Source, "Unique Names", each List.Distinct(Text.Split([Names], ","))),
    // Remove the original data column named as Names in my sample data
    RemovedOriginal = Table.RemoveColumns(AddColumn,{"Names"}),
    // Concatenate distinct list items by using the Text.Combine() function 
    // (The inner List.Transform() function in this step only makes sure converting the list items to text data type 
    Result = Table.TransformColumns(RemovedOriginal, {"Unique Names", each Text.Combine(List.Transform(_, Text.From), ","), type text})
in
    Result

Data:
1690567982558.png

After transformation:
1690568003406.png
 
Upvote 0
Or a direct transformation in the same column.

Power Query:
let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCsnP1VEIToQQSrE6YBEwDeODJcGCsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Names = _t]),
    result = Table.TransformColumns(Source,{{"Names", each Text.Combine(List.Distinct(Text.Split(_,", ")),", "), type text}})
in
    result
 
Upvote 0
Solution
Or a direct transformation in the same column.

Power Query:
let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCsnP1VEIToQQSrE6YBEwDeODJcGCsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Names = _t]),
    result = Table.TransformColumns(Source,{{"Names", each Text.Combine(List.Distinct(Text.Split(_,", ")),", "), type text}})
in
    result
This worked great, thank you for the assist!
 
Upvote 0

Forum statistics

Threads
1,223,237
Messages
6,170,924
Members
452,366
Latest member
TePunaBloke

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