Forum Discussion
Replacing values in multiple columns based on condition in Power Query
- 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
- 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.
Hey ziying35.
I included your solution in my blogpost at https://gorilla.bi/power-query/replace-values/.
However, I'm accustomed to working with Replacer.ReplaceValues and Replacer.ReplaceText. I don't fully understand your example.
Can you elaborate on the inner workings of :
(x,y,z)=> if y then z else x?
Warm regards,
Rick
x = original value
y = match condition (true or false)
z = replacement value