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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Floriankx
Solution Sage
Solution Sage

Power Query - Replace multiple substrings in one column

Hello,

 

I am looking for a solution to replace multiple substrings at once.

For Example:

CategoryCategory after
AA_AAB_A
aa_BAB_B
AA_CAB_C
BB_ADE_A
BB_BDE_B
BB_CDE_C

 

so AA->AB, aa->AB and BB->DE.

 

I found something here, but it is not able to replace substrings and it creates three single steps.

My aim would be to do it in one single step.

 

I'm really looking forward for your feedback.

1 ACCEPTED SOLUTION
v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @Floriankx,

 

Here are some blogs written about multiple replacements of words with Power Query:

Multiple replacements or translations in Power BI and Power Query

Multiple replacements of words in Power Query

Replace multiple values in a single step

 

Regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
dufoq3
Community Champion
Community Champion

I know this is old topic, but maybe it helps to someone...

 

Let's assume that you have table with replacement pairs called t_Replacements which contains Find and Replace columns:

dufoq3_1-1703255289643.png

 

Then you can add to your table new Custom Column and paste there this code
(Column with your text should have name Column1)

 

[ 
	v_replacingTable = Table.Distinct(Table.TransformColumns(t_Replacements,{{"Find", Text.Lower, type text}}), "Find"),
	v_replacingTableAsListOfLists = Table.ToRows(v_replacingTable),
	v_textAsList = Text.Split([Column1], "_"),
	v_replacedTextAsList = List.ReplaceMatchingItems(v_textAsList, v_replacingTableAsListOfLists, Comparer.OrdinalIgnoreCase),
	v_replacedTextAsText = Text.Combine(v_replacedTextAsList, "_")
][v_replacedTextAsText]

 

 

Result:

dufoq3_2-1703255384407.png

 

Note:

If you want to debug this code - just delete [v_replacedTextAsText] after ] at the end of the code and then you can expand the record to see result of each step/variable.


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Lawrenceiow
Advocate I
Advocate I

Text.Replace is case sensitive.

Text.Replace([Category],"AA","AB")

To make the three replacements you can nest it.

Text.Replace(Text.Replace(Text.Replace([Category],"BB","DE"),"aa","AB"),"AA","AB")

 

Anonymous
Not applicable

Hi, @Floriankx 

 

Try the following M formula in Query Editor:

 

Text.Combine( List.ReplaceMatchingItems(

Text.Split ([Category], ”_“), { {“AA”, “AB”} , {“aa”, ”AB“} , {“BB” , “DE” } }

))

 

Here is more information to assist you:
https://www.syntelli.com/easy-guide-to-bulk-replace-values-in-power-bi-or-power-query

 

Let me know if it works!

v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @Floriankx,

 

Here are some blogs written about multiple replacements of words with Power Query:

Multiple replacements or translations in Power BI and Power Query

Multiple replacements of words in Power Query

Replace multiple values in a single step

 

Regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

July Power BI Update Carousel

Power BI Monthly Update - July 2026

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

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

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.

Top Solution Authors