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

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

Reply
KristofferAJ
Helper III
Helper III

How can I best combine my simple 'replace' queries into one?

Hi,

I have a long list of instutution names which spelled differently, they way we are sorting these duplicates is that we have over time manually harmonized the names by replacing the 'Facility name'

 

For example:

School of Apples vs. School of Apple

 

This leaves me with many single queries in powerBI which is identical to below..

= Table.ReplaceValue(TABLE,"Name XX","Name YY",Replacer.ReplaceValue,{"COLUMN"})

 

Is there a way I can have one query which I can keep come back to and simple add a line to is, whenever I want to make a new update? - this would also allow me to use this valuable information in other reports instead of starting from scratch.

 

I have tried various of ways like below, but I keep get an error

= Table.ReplaceValue(TABLE,"Name XX","Name YY",Replacer.ReplaceValue,{"COLUMN"}) AND
Table.ReplaceValue(TABLE,"Name XX","Name YY",Replacer.ReplaceValue,{"COLUMN"}) AND
Table.ReplaceValue(TABLE,"Name XX","Name YY",Replacer.ReplaceValue,{"COLUMN"}) AND
Table.ReplaceValue(TABLE,"Name XX","Name YY",Replacer.ReplaceValue,{"COLUMN"}) AND

 

 

1 ACCEPTED SOLUTION

Hi @KristofferAJ 

 

Below is a solution. Please feel free to accept as a solution if this works for you.

 

Have a table with old and new names.

 

Thingsclump_0-1645176858751.png

 

In data table where you have all columns, create left join using old name as common column. add a conditional column that results in new column or old one if it is null. Basically if it is null, it means hospital name has not changed.

 

Thingsclump_1-1645176933817.png

 

Code for first table.

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8swrTs0pLsgsScxRCM3LLEstKgayU0uKoWJOqUV5Sjq4lSl45COrjNWJVvIvyknMS8lXcM7JzMtMBsoEpRanJhYlZyg4p+aVpBYBjcNQ4puaAqahKmJjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Old name" = _t, #"New name" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Old name", type text}, {"New name", type text}})
in
#"Changed Type"

 

 

 

Code for second tabel:

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("xZLPTgIxEMZfZcIZE3a33WWP/AngAUk0yoFwqMvINq5dMi0YfB4ewxsv5rQQSJSDJiQemk5npv31+9rZrJGIRIq8nclGs/GO1vG0QFuQXjldG4h47UsdHv1+JKN2i6NbY7GyK+1UBY9Gb5Asx+jsMddFMtw2INTPa1paR8pahKjNyVCbN5kcJzIVnEH1AxvzOvHNAZuI2FPHuNAf2mhblHjG7ncOpho9b7rflaTNEgmG+09yWDHyJux94g6jAjfNZHaZ6okpj16gxnkico5OpC3ULzDW6k3DqD4o5XIkWi24q8mV3j6IYldCZ4Nmjf7KvjtQszSXwjsZWr+BvQvRyeVYCH+LCVXKLGroVay5YFfv0aKiooQeGofkX6YlJTzUa0ZOSLHwM/m4++D04cBLZHk0+kAWeSoyrzmcGfQM0SAxfISqcmWhCM/4OIeuotcKt9DTVFSeO2AIjLds2BH9X9/rCob7D+fnv/t9TdGnz/YL3fMv", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Account number" = _t, Region = _t, Description = _t, Scale = _t, Section = _t, ID = _t, #"Facility Name" = _t, #"Facility Address" = _t, #"Facility City" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Account number", Int64.Type}, {"Region", type text}, {"Description", type text}, {"Scale", Int64.Type}, {"Section", type text}, {"ID", type text}, {"Facility Name", type text}, {"Facility Address", type text}, {"Facility City", type text}}),
#"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Facility Name"}, #"Old vs New names", {"Old name"}, "Old vs New names", JoinKind.LeftOuter),
#"Expanded Old vs New names" = Table.ExpandTableColumn(#"Merged Queries", "Old vs New names", {"New name"}, {"Old vs New names.New name"}),
#"Reordered Columns" = Table.ReorderColumns(#"Expanded Old vs New names",{"Account number", "Region", "Description", "Scale", "Section", "ID", "Facility Address", "Facility City", "Facility Name", "Old vs New names.New name"}),
#"Added Conditional Column" = Table.AddColumn(#"Reordered Columns", "New name", each if [Old vs New names.New name] = [Facility Name] then [Old vs New names.New name] else [Facility Name])
in
#"Added Conditional Column"

 

Thanks,

Thingsclump

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

If you have the replacement values either in a two column table, or in one column or

list of text like "Apple schools", "Apple School", then you can do:

 

= Table.FromRows(List.ReplaceMatchingItems(Table.ToRows(TableOrPriorStepName), each _, List.Zip({ReplacementTable[Column1], ReplacementTable[Column2]}))


Basically making your rows into a list, and then Zipping your replacement values together by position so you get the {{"apple schools", "Apple School"}, {"old schools", "New School"}} format that is required for List.TransformMatchingItems.

 

Give that a shot, I might have a parenthesis or bracket missing or in the wrong place, but I gotta get these dishes done.

 

--Nate

KristofferAJ
Helper III
Helper III

For instance similar to this, which change the type of columns for three columns in a go...

= Table.TransformColumnTypes
(#"site_Sheet",{{"Column1", type text}, {"Column2", type text}, {"Column54", type text}})

KNP
Super User
Super User

@KristofferAJ - I'd probably do this with a mapping table and functions. It makes it easier to maintain.

 

Check out this post...

https://community.powerbi.com/t5/Power-Query/Function-to-Replace-values-in-one-column-based-on-entri...

 

Specifically, the answer from @ImkeF, and the PBIX she attached.

 

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
xOIEmaj

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
image
fabric-SUbadge
Proud to be a Super User!
KristofferAJ
Helper III
Helper III

Hi @Thingsclump 

Absolutely! - I have attached my example. In this case I have two duplicates I solve my replacing the Column name 'Facility Name':

 

That would be two steps in the query:

1.

= Table.ReplaceValue(BOOK1,"Inselspital Universitaetsspital Bern","Inselspital Universitaets Hospital Bern",Replacer.ReplaceValue,{"Facility Name"})

 

2.
= Table.ReplaceValue(BOOK1,"Orlando Clinical Research Center","Orlando Clinical Medical Center",Replacer.ReplaceValue,{"Facility Name"})

 

My big question can I combine these identical queries in one step? -and then each time I have a new simple update the same query with a new line?

Thanks

KRistoffer 


 

Account numberRegionDescriptionScaleSectionIDFacility NameFacility AddressFacility City
343549875westdescription 15ADD15180Inselspital Universitaetsspital BernFreiburgstrasse 18Bern
323564eastdescription 23BDD3420Medizinische Universität WienWähringer Gürtel 18-20Vienna
6757eastdescription 36CDD29349University of Miami Hospital1400 Northwest 12th AvenueMiami
769545Northdescription 41ADD2446Orlando Clinical Research Center5055 South Orange AvenueOrlando
3446Northdescription 53ADD496479Southwest General Healthcare Center29 Barkley CircleFort Myers
343549875westdescription 15ADD15180Inselspital Universitaetsspital BernFreiburgstrasse 18Bern
769545Northdescription 41ADD2446Orlando Clinical Medical Center5055 South Orange AvenueOrlando
343549875westdescription 15ADD15180Inselspital Universitaets Hospital BernFreiburgstrasse 18Bern

 

Hi @KristofferAJ 

 

Below is a solution. Please feel free to accept as a solution if this works for you.

 

Have a table with old and new names.

 

Thingsclump_0-1645176858751.png

 

In data table where you have all columns, create left join using old name as common column. add a conditional column that results in new column or old one if it is null. Basically if it is null, it means hospital name has not changed.

 

Thingsclump_1-1645176933817.png

 

Code for first table.

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8swrTs0pLsgsScxRCM3LLEstKgayU0uKoWJOqUV5Sjq4lSl45COrjNWJVvIvyknMS8lXcM7JzMtMBsoEpRanJhYlZyg4p+aVpBYBjcNQ4puaAqahKmJjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Old name" = _t, #"New name" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Old name", type text}, {"New name", type text}})
in
#"Changed Type"

 

 

 

Code for second tabel:

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("xZLPTgIxEMZfZcIZE3a33WWP/AngAUk0yoFwqMvINq5dMi0YfB4ewxsv5rQQSJSDJiQemk5npv31+9rZrJGIRIq8nclGs/GO1vG0QFuQXjldG4h47UsdHv1+JKN2i6NbY7GyK+1UBY9Gb5Asx+jsMddFMtw2INTPa1paR8pahKjNyVCbN5kcJzIVnEH1AxvzOvHNAZuI2FPHuNAf2mhblHjG7ncOpho9b7rflaTNEgmG+09yWDHyJux94g6jAjfNZHaZ6okpj16gxnkico5OpC3ULzDW6k3DqD4o5XIkWi24q8mV3j6IYldCZ4Nmjf7KvjtQszSXwjsZWr+BvQvRyeVYCH+LCVXKLGroVay5YFfv0aKiooQeGofkX6YlJTzUa0ZOSLHwM/m4++D04cBLZHk0+kAWeSoyrzmcGfQM0SAxfISqcmWhCM/4OIeuotcKt9DTVFSeO2AIjLds2BH9X9/rCob7D+fnv/t9TdGnz/YL3fMv", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Account number" = _t, Region = _t, Description = _t, Scale = _t, Section = _t, ID = _t, #"Facility Name" = _t, #"Facility Address" = _t, #"Facility City" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Account number", Int64.Type}, {"Region", type text}, {"Description", type text}, {"Scale", Int64.Type}, {"Section", type text}, {"ID", type text}, {"Facility Name", type text}, {"Facility Address", type text}, {"Facility City", type text}}),
#"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Facility Name"}, #"Old vs New names", {"Old name"}, "Old vs New names", JoinKind.LeftOuter),
#"Expanded Old vs New names" = Table.ExpandTableColumn(#"Merged Queries", "Old vs New names", {"New name"}, {"Old vs New names.New name"}),
#"Reordered Columns" = Table.ReorderColumns(#"Expanded Old vs New names",{"Account number", "Region", "Description", "Scale", "Section", "ID", "Facility Address", "Facility City", "Facility Name", "Old vs New names.New name"}),
#"Added Conditional Column" = Table.AddColumn(#"Reordered Columns", "New name", each if [Old vs New names.New name] = [Facility Name] then [Old vs New names.New name] else [Facility Name])
in
#"Added Conditional Column"

 

Thanks,

Thingsclump

Thingsclump
Resolver V
Resolver V

Hi @KristofferAJ 

 

Can you share sample data in table format removing senstive information. This will help to give precise solution.

 

Thanks

www.thingsclump.com

 

Helpful resources

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

Top Kudoed Authors