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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
AmyBeth
New Member

Remove repeated text within a row

Good morning,

How can I remove repeating values across columns within a row?  I don't have a fixed delimiter to split the cells.  Is there any logic that can look within the row and remove contents that are in column A from Column B for example?   Unfortunately my data is confidential but  tried to create an example using common data below.  I appreciate any help you can offer!  

Thanks!

Amy

 

Column AColumn BColumn CColumn D
Amy BethAmy Beth SmithAmy Beth Smith MsAmy Beth Smith MS and Family
IshaanIshaan JaglanIshaan Jaglan IIIshaan Jaglan II with Guest
    
DESIRED DATASET   
Amy BethSmithMsand Family
IshaanJaglanIIwith Guest
1 ACCEPTED SOLUTION
ImkeF
Community Champion
Community Champion

Hi @AmyBeth 

you can strip out the occurrences of the strings from "ColumnA" from other columns like so:

 

Text.Replace([ColumnName], [Column A], "")

 

If you have many columns, unpivoting and pivoting back might be the most efficient solution:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcsytVHBKLclQ0oEzFYJzM7EIKPgWYxELVkjMS1FwS8zNzKlUitWJVvIszkhMzAOqhDAUvBLTczD5Cp6eWIQUykFmupemFpcoxcYCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"Column A" = _t, #"Column B" = _t, #"Column C" = _t, #"Column D" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column A", type text}, {"Column B", type text}, {"Column C", type text}, {"Column D", type text}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Column A"}, "Attribute", "Value"),
    #"Added Custom" = Table.AddColumn(#"Unpivoted Other Columns", "Custom", each Text.Replace([Value], [Column A], "")),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Value"}),
    #"Trimmed Text" = Table.TransformColumns(#"Removed Columns",{{"Custom", Text.Trim, type text}}),
    #"Pivoted Column" = Table.Pivot(#"Trimmed Text", List.Distinct(#"Trimmed Text"[Attribute]), "Attribute", "Custom")
in
    #"Pivoted Column"

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

1 REPLY 1
ImkeF
Community Champion
Community Champion

Hi @AmyBeth 

you can strip out the occurrences of the strings from "ColumnA" from other columns like so:

 

Text.Replace([ColumnName], [Column A], "")

 

If you have many columns, unpivoting and pivoting back might be the most efficient solution:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcsytVHBKLclQ0oEzFYJzM7EIKPgWYxELVkjMS1FwS8zNzKlUitWJVvIszkhMzAOqhDAUvBLTczD5Cp6eWIQUykFmupemFpcoxcYCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"Column A" = _t, #"Column B" = _t, #"Column C" = _t, #"Column D" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column A", type text}, {"Column B", type text}, {"Column C", type text}, {"Column D", type text}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Column A"}, "Attribute", "Value"),
    #"Added Custom" = Table.AddColumn(#"Unpivoted Other Columns", "Custom", each Text.Replace([Value], [Column A], "")),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Value"}),
    #"Trimmed Text" = Table.TransformColumns(#"Removed Columns",{{"Custom", Text.Trim, type text}}),
    #"Pivoted Column" = Table.Pivot(#"Trimmed Text", List.Distinct(#"Trimmed Text"[Attribute]), "Attribute", "Custom")
in
    #"Pivoted Column"

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors