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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

How to replace a string value if another string value exists in the cell ?

Hello,

 

How to replace a string value if another string value is present in the cell? example :

 

Data = aaa bbb ccc ddd eee fff

 

I'm looking to replace only "eee" with "xxx-eee", only if "bbb" exists ont the cell?

 

Thanks!

1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

@Anonymous Well, in DAX that is simply:

Column = IF(SEARcH("bbb", [Column1],,0)>1,SUBSTITUTE([Column1],"eee","xxx-eee"),[Column1])

Let me see if I can figure out the Power Query.



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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

5 REPLIES 5
Greg_Deckler
Community Champion
Community Champion

@Anonymous OK, here is an inefficent way to do it in Power Query but something that can be done completely from the UI.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSkxMVEhKSlJITk5WSElJUUhNTVVIS0tTitWByGGIxwIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
    #"Duplicated Column" = Table.DuplicateColumn(#"Changed Type", "Column1", "Column1 - Copy"),
    #"Replaced Value" = Table.ReplaceValue(#"Duplicated Column","eee","xxx-eee",Replacer.ReplaceText,{"Column1 - Copy"}),
    #"Added Conditional Column1" = Table.AddColumn(#"Replaced Value", "Custom", each if Text.Contains([Column1], "bbb") then [#"Column1 - Copy"] else [Column1]),
    #"Removed Columns1" = Table.RemoveColumns(#"Added Conditional Column1",{"Column1", "Column1 - Copy"})
in
    #"Removed Columns1"

 



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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

If you're willing to venture beyond the UI, you can recreate @Greg_Deckler's solution within the replacement step.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSkxMVEhKSlJITk5WSElJUUhNTVVIS0tTitWByAH5SrGxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    #"Replaced Value" = Table.ReplaceValue(Source, each if Text.Contains([Column1],"bbb") then "eee" else null, "xxx-eee", Replacer.ReplaceText, {"Column1"})
in
    #"Replaced Value"

 

Anonymous
Not applicable

Thanks a lot!

Greg_Deckler
Community Champion
Community Champion

@Anonymous Well, in DAX that is simply:

Column = IF(SEARcH("bbb", [Column1],,0)>1,SUBSTITUTE([Column1],"eee","xxx-eee"),[Column1])

Let me see if I can figure out the Power Query.



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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Thanks! I need it write with M please

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

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