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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
oswin_aria
New Member

Replace Multiple Values (Character) Inside a Value (Column)

Hello there..

 

I just want to do simple thing: to replace number 1, 2, 3 (only this three number, not all number) with letter "X" using Power Query..
Like this one:

oswin_aria_0-1721743046401.png

But instead using Replace Value three times like this:

oswin_aria_1-1721743108765.png

 

Is there another more simple way?

I've tried using formula with array:

  • = Table.ReplaceValue(#"Replaced Value",("1","2","3"),"X",Replacer.ReplaceText,{"Coba"})
  • = Table.ReplaceValue(#"Replaced Value",{"1","2","3"},"X",Replacer.ReplaceText,{"Coba"})

But none of them works..

 

Thank you

 

3 ACCEPTED SOLUTIONS
collinq
Super User
Super User

Hi @oswin_aria ,

 

As always, in Power Query, there are many different ways to do the same thing.  So, my way might not be the absolute best way but it works for me!  😁

I had this as my test data:

collinq_0-1721762293509.png


And I was able to convert it to this:

collinq_1-1721762341335.png


In one replace rather than three.  Here is the M code that I used:
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
Replace123 = (text as text) as text => Text.Replace(Text.Replace(Text.Replace(text, "1", "x"), "2", "x"), "3", "x"),
#"Replaced Values" = Table.TransformColumns(#"Changed Type",{{"Column1", each Replace123(_), type text}})
in
#"Replaced Values"




Did I answer your question? Mark my post as a solution!

Proud to be a Datanaut!
Private message me for consulting or training needs.




View solution in original post

Anonymous
Not applicable

Hi @oswin_aria ,


Provide another idea:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQydnRyVorVATIdjZyMoUxDR0cjIycnY2NnoEAsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Coba = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Coba", type text}}),
    CharsToReplace = {"1", "2", "3"},
    ReplaceWith = "X",
    ReplacedText = Table.TransformColumns(#"Changed Type",{{"Coba", each List.Accumulate(CharsToReplace, _, (state, current) => Text.Replace(state, current, ReplaceWith))}})
in
    ReplacedText

vcgaomsft_0-1721784012190.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum -- China Power BI User Group

View solution in original post

dufoq3
Super User
Super User

Hi @oswin_aria, another solution:

 

Result

dufoq3_0-1721806094033.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQydnRyVorVATIdjZyMoUxDR0cjIycnY2NnoEAsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Coba = _t]),
    AddedCustom = Table.AddColumn(Source, "Custom", each Text.Combine(List.ReplaceMatchingItems(Text.ToList([Coba]), {{"1", "X"}, {"2", "X"}, {"3", "X"}})), type text)
in
    AddedCustom

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

View solution in original post

4 REPLIES 4
dufoq3
Super User
Super User

Hi @oswin_aria, another solution:

 

Result

dufoq3_0-1721806094033.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQydnRyVorVATIdjZyMoUxDR0cjIycnY2NnoEAsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Coba = _t]),
    AddedCustom = Table.AddColumn(Source, "Custom", each Text.Combine(List.ReplaceMatchingItems(Text.ToList([Coba]), {{"1", "X"}, {"2", "X"}, {"3", "X"}})), type text)
in
    AddedCustom

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Anonymous
Not applicable

Hi @oswin_aria ,


Provide another idea:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQydnRyVorVATIdjZyMoUxDR0cjIycnY2NnoEAsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Coba = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Coba", type text}}),
    CharsToReplace = {"1", "2", "3"},
    ReplaceWith = "X",
    ReplacedText = Table.TransformColumns(#"Changed Type",{{"Coba", each List.Accumulate(CharsToReplace, _, (state, current) => Text.Replace(state, current, ReplaceWith))}})
in
    ReplacedText

vcgaomsft_0-1721784012190.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum -- China Power BI User Group

collinq
Super User
Super User

Hi @oswin_aria ,

 

As always, in Power Query, there are many different ways to do the same thing.  So, my way might not be the absolute best way but it works for me!  😁

I had this as my test data:

collinq_0-1721762293509.png


And I was able to convert it to this:

collinq_1-1721762341335.png


In one replace rather than three.  Here is the M code that I used:
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
Replace123 = (text as text) as text => Text.Replace(Text.Replace(Text.Replace(text, "1", "x"), "2", "x"), "3", "x"),
#"Replaced Values" = Table.TransformColumns(#"Changed Type",{{"Column1", each Replace123(_), type text}})
in
#"Replaced Values"




Did I answer your question? Mark my post as a solution!

Proud to be a Datanaut!
Private message me for consulting or training needs.




It works like magic! Thanks a lot...

Helpful resources

Announcements
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.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

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