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

Replace values/Data Transformation Power Query Performance

Hi Power BI Community,

I needed to do a lot of changes in my Power Query. This is not good for the perfomance. 

Why does Power Query dont summarize these steps.

Beginner_2020_0-1612774947165.png


Data looks like this: 
= Table.ReplaceValue(#"Replaced Value57","AIMS 45-193i","AIMS",Replacer.ReplaceText,{"Tool Cluster"})
= Table.ReplaceValue(#"Replaced Value56","MeRiT MG 45","MeRiT",Replacer.ReplaceText,{"Tool Cluster"})

How can I combine this steps and also speed up the overall performance?

 

1 ACCEPTED SOLUTION
v-yingjl
Community Support
Community Support

Hi @Anonymous ,

You can refer these documents to create a replacetable and a custom function to replace multiple fields at once:

  1. Multiple replacements or translations in Power BI and Power Query 
  2. Multiple Replacements of words in Power Query 
  3. Replace multiple values in a single step 
let 
    ReplaceAll = (InputTable as table, ColumnName as text,ReplacementTable as table, optional StartRow as number) =>
    let
    ActualRow = if StartRow = null then 0 else StartRow,
    result = Table.ReplaceValue(InputTable,ReplacementTable{ActualRow}[Old],ReplacementTable{ActualRow}[New],Replacer.ReplaceText,{ColumnName}),
    NextRow = ActualRow + 1,
    OutputTable = if NextRow > (Table.RowCount(ReplacementTable)-1) then result 
    else
    @ReplaceAll(result,ColumnName,ReplacementTable,NextRow)
    in
    OutputTable
    in 
    ReplaceAll

Attached a sample file in the below, hopes it could help.

 

Best Regards,
Community Support Team _ Yingjie Li
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

2 REPLIES 2
v-yingjl
Community Support
Community Support

Hi @Anonymous ,

You can refer these documents to create a replacetable and a custom function to replace multiple fields at once:

  1. Multiple replacements or translations in Power BI and Power Query 
  2. Multiple Replacements of words in Power Query 
  3. Replace multiple values in a single step 
let 
    ReplaceAll = (InputTable as table, ColumnName as text,ReplacementTable as table, optional StartRow as number) =>
    let
    ActualRow = if StartRow = null then 0 else StartRow,
    result = Table.ReplaceValue(InputTable,ReplacementTable{ActualRow}[Old],ReplacementTable{ActualRow}[New],Replacer.ReplaceText,{ColumnName}),
    NextRow = ActualRow + 1,
    OutputTable = if NextRow > (Table.RowCount(ReplacementTable)-1) then result 
    else
    @ReplaceAll(result,ColumnName,ReplacementTable,NextRow)
    in
    OutputTable
    in 
    ReplaceAll

Attached a sample file in the below, hopes it could help.

 

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

amitchandak
Super User
Super User

@Anonymous , see if this blog on bulk replace can help

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

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.