Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
D_PBI
Post Patron
Post Patron

How to concatenate two column, removing duplicates in DAX?

Hi,
Please view the below table:

table.JPG

 

The above table has two columns Lead and Contributor that I need to concatenate, removing any duplicates but keeping the brackets from the Lead column. The table also shows the Final column. It is this Final column that I need to produce using DAX.
If you look at each row you will see that the values from the Lead column, with their brackets, are always kept. Any names in the Contributor column that are also in the Lead column need to be removed. It is only the non-duplicated names that should be kept, without brackets.

I think the above table explains all clearly.
Hope do I achieve this?
Thanks.

1 ACCEPTED SOLUTION
mahoneypat
Employee
Employee

Here is one way to do it. Add a custom column with this expression.

 

let
leadlist = Text.Split(Text.Replace(Text.Replace([Lead], "{", ""), "}", ""), ", "),
contriblist = Text.Split([Contributor], ", "),
removedupes = List.Distinct(List.RemoveMatchingItems(contriblist, leadlist)),
result = [Lead] & ", " & Text.Combine(removedupes, ", ")
in
result

 

mahoneypat_0-1641907183528.png

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

3 REPLIES 3
mahoneypat
Employee
Employee

Here is one way to do it. Add a custom column with this expression.

 

let
leadlist = Text.Split(Text.Replace(Text.Replace([Lead], "{", ""), "}", ""), ", "),
contriblist = Text.Split([Contributor], ", "),
removedupes = List.Distinct(List.RemoveMatchingItems(contriblist, leadlist)),
result = [Lead] & ", " & Text.Combine(removedupes, ", ")
in
result

 

mahoneypat_0-1641907183528.png

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Can you share this sample file. I am facing problem to concatenate 2 strings without duplicates. Where should I need to write that Query. If am writing in Advanced editor I got error

@mahoneypat  - thanks for the prompt response - it works nicely.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.