Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Replacing values in one column with values from another table

Hi, I want to replace values in one table using another table as a reference/lookup. I have tried to add the following as a step in my orginal tables    = Table.ReplaceValue ( #"Changed Type",eac...
  • v-angzheng-msft's avatar
    4 years ago

    Hi, Anonymous 

     

    Check whether the above search column text contains invisible characters. The simple way to avoid this error is to copy and paste the column name.

     

    refer:

    Table.ReplaceValue

    Table.ReplaceValue(table as table, oldValue as any, newValue as any, replacer as function, columnsToSearch as list) as table

     

    Here is a solution I thought of, which may help you.

    I encapsulated a function that replaces the value, which can be called on the column. This works for all columns.

    Create a blank query, open Advanced Editor and replace the text there with the code below.  In your original query, you can then go to the Add Column tab, invoke custom function and choose this function and choose your "Old" column as the input.

     

    (inputtext as text) =>
    let 
    Result = List.ReplaceMatchingItems(Table.ToList(Table.FromValue(Text.From(inputtext))), List.Zip({Amendments[Current], Amendments[Replace]}))
    in 
    Result{0}

    Result:

     

     

    Please refer to the attachment below for details. Hope this helps.

     

     

     

    Best Regards,
    Community Support Team _ Zeon Zheng


    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.