Forum Discussion
ChemEnger
Advocate V
2 years agoDynamically apply column transformations
I have a 'data' table where I'd like to dynamically change the number of decimal places. I use a 'dictionary' table that holds the names of the columns in 'data' along with the desired number of dec...
- 2 years ago
Hi ChemEnger ,
it could work like so:(InputTable as table, dictionary as table) => let TransformFunctionList = List.Transform( Table.ToRecords(dictionary), (record) => {record[ColumnName], each Number.Round(_, record[Decimal]), type number} ), Transform = Table.TransformColumns(InputTable, TransformFunctionList) in TransformNo real recursion needed. Just transform your dictionary table into a list of records and create the transformation list elements out of it.
ImkeF
Community Champion
2 years agoHi ChemEnger ,
it could work like so:
(InputTable as table, dictionary as table) =>
let
TransformFunctionList = List.Transform(
Table.ToRecords(dictionary),
(record) => {record[ColumnName], each Number.Round(_, record[Decimal]), type number}
),
Transform = Table.TransformColumns(InputTable, TransformFunctionList)
in
Transform
No real recursion needed. Just transform your dictionary table into a list of records and create the transformation list elements out of it.
ChemEnger
Advocate V
2 years agoSpot on, thank you ImkeF.
I was looking at something similar on Medium - Transform Multiple Columns Based On Other Columns In Power Query but your solution worked first time 🙂