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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Bulk replace text without custom function or tables

I've read a lot of posts about how to perform multiple value replacements in a column without resorting to the inefficient use of multiple single replacement steps which in my case was causing over 15 minutes to apply a change in power query due to millions of rows.

Most of the solutions I found use custom functions, lists or switch tables, all of which work but seemed more complicated than I needed.

I was playing around with M query and the solution below works for me.

I used the GUI to create the first replacement, then extended it out to include other criteria.

The example below uses Replacer.ReplaceValue so will match against the whole cell value.

To match against any portion of a cell value change to Replacer.ReplaceText

The part I like about this is you can also use it for replacement based on a value in a different column to the one you are performing (e.g. replace value in column 1 based on value in column 2 in same row) the replacement on by just changing the column heading after the if statement.

E.g:

#"Replaced Values in Column1" = Table.ReplaceValue(Source, each [Column1],
each if [Column1]="i spelt this uncorrectly" then "This is how to spell it"
else if [Column1]="i really can't type well" then "This is how to type well"
else if [Column1]="i want to use a custom power query function" then "I do not want to use a custom PQ function if I can avoid it!else [Column1], Replacer.ReplaceValue,{"Column1})

1 REPLY 1
Greg_Deckler
Super User
Super User

Nice!

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors