Forum Discussion
Converting whole numbers to decimals with row-wise division
- 1 year ago
Table.FromList( Table.ToList( Tbl, (x) => List.FirstN(x, 2) & List.Transform( List.Skip(x, 3), (z) => if x{2} = 0 then null else z / x{2} ) ), each _, List.RemoveRange(Table.ColumnNames(Tbl), 2, 1) )
Table.FromList(
Table.ToList(
Tbl,
(x) => List.FirstN(x, 2) &
List.Transform(
List.Skip(x, 3),
(z) => if x{2} = 0 then null else z / x{2}
)
),
each _,
List.RemoveRange(Table.ColumnNames(Tbl), 2, 1)
)Hey AlienSX, just a curiosity... I thought Table.ToList() would object to any non-text values unless you gave it an explicit type conversion argument of some kind. But your code works when my input Tbl has Int64 or decimal types in the conversion columns. I don't understand which element of your solution is getting around this type restriction.
- AlienSx1 year ago
Super User
Hello, CCHarrison there is no type restriction when you explicitly define "combiner" function as 2nd argument. This argument (optional combiner as nullable function) is optional. If you don't use it (or use null) then Table.ToList applies default Combiner.CombineTextByDelimiter(",") which in turn requires a list of values of type text.
But when you define your own "combiner" function then it's all yours. This "combiner" function must be a function of single argument. Table.ToList will pass the list of row values to your function. Try simplest (x) => x and see the result.