Forum Discussion
EmanueleP
4 years agoRegular Visitor
Replace Value in multiple columns with different conditional rules on each column
Hello, I am new to M and I need some help. I need to perform an operation cycling like a for loop. I have a List containing the Columns Name in text format on which I want to run the cycling ope...
- 4 years ago
Hi EmanueleP,
I think your choice could be List.Accumulate as the input is already arranged in a list. This is the snippet of how you could apply it.
let ... mytab2= ...//table DynamicCol = Table.ColumnNames(mytab2), fProcessColumns = (t as table, col as text)=> Table.ReplaceValue( t, each Record.Field(_,col), each if Record.Field(_,"Levelcount")=Number.FromText(Text.End(col,1)) then Record.Field(_,"newPN") else "",Replacer.ReplaceText,{col} ), Process = List.Accumulate(DynamicCol, mytab2, (a, n)=> fProcessColumns(a,n)) in ProcessP.S. I would sill recommend to read the article referred by Anonymous, this is quite interesting code/solution.
Kind regards,
John
EmanueleP
4 years agoRegular Visitor
Thanks, this works!! I will also have a look at the article which seems interesting.