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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
jsherman-q
New Member

replace value in column1 using value in column2

I am trying to remove the vlaue of column1 from column2. For example, column1 has the file extension of a file name in column2, I would like to remove the file extension from column2. So sort of a dynamic replace, using a column value as the search text and replacing it with blank.

1 ACCEPTED SOLUTION
AlB
Community Champion
Community Champion

@jsherman-q 

Please always share a sample of your data to make it easier for those trying to answer

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W0iupKFHSUcpLzE01BLNjdYCCqRWpUEEjMBssmJQIU2kMZsfGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Text.Replace([Column2],[Column1],""))
in
    #"Added Custom"

 

Please mark the question solved when done and consider giving kudos if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

View solution in original post

4 REPLIES 4
Greg_Deckler
Super User
Super User

@jsherman-q - I would just create a new column that does the necessary operation, remove the original column and then rename the new column to the old colum, like this:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W0itIyqxQ0lHKz0uFMGN1gIJJiSVAsZLyfDALLFSRUwxSV5JRlJoK4cTGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}}),
    #"Inserted Text Before Delimiter" = Table.AddColumn(#"Changed Type", "Text Before Delimiter", each Text.BeforeDelimiter([Column2], "."), type text),
    #"Removed Columns" = Table.RemoveColumns(#"Inserted Text Before Delimiter",{"Column2"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Text Before Delimiter", "Column2"}})
in
    #"Renamed Columns"


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

If i'm reading that right it looks like it just remvoed the text before the delimiter ".". If so, that's not really what i want. I want ot to remove the value in column1 from column2. I used the exmaple of a file extension but in some cases my data is not a file extension and does not have the ".". 

AlB
Community Champion
Community Champion

@jsherman-q 

Please always share a sample of your data to make it easier for those trying to answer

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W0iupKFHSUcpLzE01BLNjdYCCqRWpUEEjMBssmJQIU2kMZsfGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Text.Replace([Column2],[Column1],""))
in
    #"Added Custom"

 

Please mark the question solved when done and consider giving kudos if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

That worked thank you. I would have psoted data but it I is private data so I would have had to come up with sample data, which I was hoping I wouldn't have had to. 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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

Top Solution Authors