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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
sonnh
Frequent Visitor

Power query - Replace multiple words in column using other table.

Hello all,
I have a raw data needed to be procesed by replace multiple words by this table.
OriginReplace

,DistrictDistrict
,districtDistrict
DistDistrict

I found solution here https://www.thebiccountant.com/2016/05/22/multiple-replacements-in-power-bi-and-power-query/
And write following query:
#"Added Custom" = Table.AddColumn(#"Replaced Value3", "district_test", each Text.Combine(List.ReplaceMatchingItems(Text.Split([District]," "), Convert[Liste])," ")),
But this solution is only suitable for replace single word to single word. If I want replace multiple word like below table, it can not work because Text.Split use space as delimiter.
OriginReplace

, District 01District 1
,district 002District 2
Dist 10District 10

This convert table have many rows and need to be added more words in future, so I don't want replace manually.

Can you give me advice or solution for this case.
Thanks in advance.

1 ACCEPTED SOLUTION
Vera_33
Resident Rockstar
Resident Rockstar

Hi @sonnh 

 

I have adapted one custom function applied to different cases, you can have a look and modify accordingly, credit to original author:

https://www.howtoexcel.org/power-query/bulk-replace-values/

 

Vera_33_0-1625202517732.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W0lFwySwuKcpMLlEwMFSK1QGKpMAFDIzAIiAVCoYGSrGxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Origin = _t]),
    BulkReplace = (DataTable as table, FindReplaceList as list, DataTableColumn as list) =>
    let   
        Counter = List.Count(FindReplaceList),
        BulkReplaceValues = (DataTableTemp, n) => 
        let 
            ReplaceTable = Table.ReplaceValue(
                DataTableTemp,
                FindReplaceList{n},
                "District",
                Replacer.ReplaceText,
                DataTableColumn
                )
        in

            if n = Counter - 1 
                then ReplaceTable
                else @BulkReplaceValues(ReplaceTable, n + 1),
        Output = BulkReplaceValues(DataTable, 0)   
    in
        Output,

    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Origin", type text}}),
    Custom1 = BulkReplace( #"Changed Type",{", District",",district","Dist"},{"Origin"})
in
    Custom1

 

View solution in original post

1 REPLY 1
Vera_33
Resident Rockstar
Resident Rockstar

Hi @sonnh 

 

I have adapted one custom function applied to different cases, you can have a look and modify accordingly, credit to original author:

https://www.howtoexcel.org/power-query/bulk-replace-values/

 

Vera_33_0-1625202517732.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W0lFwySwuKcpMLlEwMFSK1QGKpMAFDIzAIiAVCoYGSrGxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Origin = _t]),
    BulkReplace = (DataTable as table, FindReplaceList as list, DataTableColumn as list) =>
    let   
        Counter = List.Count(FindReplaceList),
        BulkReplaceValues = (DataTableTemp, n) => 
        let 
            ReplaceTable = Table.ReplaceValue(
                DataTableTemp,
                FindReplaceList{n},
                "District",
                Replacer.ReplaceText,
                DataTableColumn
                )
        in

            if n = Counter - 1 
                then ReplaceTable
                else @BulkReplaceValues(ReplaceTable, n + 1),
        Output = BulkReplaceValues(DataTable, 0)   
    in
        Output,

    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Origin", type text}}),
    Custom1 = BulkReplace( #"Changed Type",{", District",",district","Dist"},{"Origin"})
in
    Custom1

 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

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