Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Find and replace one specific value in a row

Hi everyone, In Power BI, I am currently using a table with about 8M transactions from an SQL query. For one very specific transaction, I want to change the SKU name and replace it with a differen...
  • Anonymous's avatar
    Anonymous
    6 years ago

    If you are sure there is only one record matching criteria, you can use this line of code:

     

    = Table.ReplaceMatchingRows(yourTab, {Table.SelectRows(yourTab, each [name]="Client3" and [amount]=610){0},[name="Client3",amount=610,SKU=newValue]})

     

    Otherwise, in case of multiple rows matching the criteria, try this:

     

     

    Table.ReplaceMatchingRows(yourTab, List.Zip({Table.ToRecords(Table.SelectRows(yourTab, each [name]="Client3" and [amount]=610)), List.Repeat({[name="Client3",amount=610,SKU=newValue]}, List.Count(Table.ToRecords(Table.SelectRows(yourTab, each [name]="Client3" and [amount]=610))))}))

     

    PS

    In case of duplicate rows, seems there is some problems. But I didn't investigate furter .