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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request 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
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.