Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Replacing values in multiple columns based on condition in Power Query

Hello,   I have a table like this: Date     plan         unplan         internal         external         production          day flag     1/1/2020     0 0 50 70 6000 Production ...
  • ziying35's avatar
    6 years ago

    Hi, Anonymous 

    Based on the simulated data source and the data processing logic you provided, write the query code like this:

    = Table.ReplaceValue(Source, each [day flag]="Down Day", null, (x,y,z)=> if y then z else x, List.Range(Table.ColumnNames(Source),1,4))

    If my code solves your problem, mark it as a solution

  • v-alq-msft's avatar
    6 years ago

    Hi, Anonymous 

     

    As what is suggested by ziying35 , I created data to reproduce your scenario. The pbix file is attached in the end.

    Table:

     

    You may insert a new step as below. On your side, you may add all corresponding columns in {"plan","unplan","internal","external",...}.

    = Table.ReplaceValue(Source, each [day flag]="Down Day", null, (x,y,z)=> if y then z else x, List.Select(Table.ColumnNames(#"Changed Type"),
    each  List.Contains( {"plan","unplan","internal","external"},_)
    )
    )

     

    Result:

     

    Best Regards

    Allan

     

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