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

Try your skills in the Power BI Dataviz World Championship! Round one ends June 26. Join now

Reply
Rozan
New Member

ReplaceValue multiple values from a mapping table

Hello everyone, Would appreciate some hints on how to replace multiple values (ideally from another mapping table).

 

The challenge I'm facing is: to replace several values in two columns ("Column 1","Column 2"), I used a stupid way to use several ReplaceValue lines and pls find a sample as below:

 

#"Replaced Value1" = Table.ReplaceValue(#"Added Custom1","Ltd.","",Replacer.ReplaceText,{"Column 1","Column 2"}),

#"Replaced Value2" = Table.ReplaceValue(#"Replaced Value1","Co.","",Replacer.ReplaceText,{"Column 1","Column 2"}),

#"Replaced Value3" = Table.ReplaceValue(#"Replaced Value2","China","CN",Replacer.ReplaceText,{"Column 1","Column 2"}), #"Replaced Value4" = Table.ReplaceValue(#"Replaced Value3","CHN","CN",Replacer.ReplaceText,{"Column 1","Column 2"}), #"Replaced Value5" = Table.ReplaceValue(#"Replaced Value4","(","",Replacer.ReplaceText,{"Column 1","Column 2"}),

#"Replaced Value6" = Table.ReplaceValue(#"Replaced Value5",")","",Replacer.ReplaceText,{"Column 1","Column 2"}),

...

 

Is there a simple way that I can put all replacement values to a mapping table (from "Ltd." to "", from "Co." to "", etc), and in the future, I can easily add more mapping values? thanks a lot.

2 REPLIES 2
ThxAlot
Super User
Super User

Simple enough, use embedded Table.ReplaceValue().

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8ilJ0VPSUXLO11OK1YFwFUAcoJCHH1jIOSMzLxHI19RUcIEIACV0lDRASjXBAo5OzgoaQE2aQOH8ikKwWEREBMgMsN7YWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]),
    Replacement = {
        {{"Ltd.","Co.","(",")"}, ""}
        , {{"China","CHN"}, "CN"}
    },
    Replaced = List.Accumulate(Replacement, Source, (s,c) => Table.ReplaceValue(s, c{0}, c{1}, (x,y,z) => List.Accumulate(y, x, (s,c) => Text.Replace(s, c, z)), {"Column1","Column2"}))
in
    Replaced

 



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LearnAndPractise(Everyday)


)



JoeBarry
Solution Sage
Solution Sage

Hi @Rozan 

 

You could probably be able to use fuzzy merge https://learn.microsoft.com/en-us/power-query/merge-queries-fuzzy-match and be able to use a mapping table too. 

 

Joe

 

If this post helps, then please Accept it as the solution

 

 

Helpful resources

Announcements
Fabric Data Days is here Carousel

Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

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.