Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hello all,
I have a raw data needed to be procesed by replace multiple words by this table.
OriginReplace
,District | District |
,district | District |
Dist | District |
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 01 | District 1 |
,district 002 | District 2 |
Dist 10 | District 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.
Solved! Go to Solution.
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/
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
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/
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
Check out the July 2025 Power BI update to learn about new features.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
User | Count |
---|---|
72 | |
71 | |
37 | |
31 | |
27 |
User | Count |
---|---|
91 | |
49 | |
45 | |
38 | |
36 |