Forum Discussion
StefanoT1982
1 year agoRegular Visitor
Evaluating a column through steps without hardcoding the steps' names
Assume I have a simple table with 2 steps: let Step1 = #table (type table[Names = Text.Type, Money = Int64.Type], {{"John", 1}, {"Jack", 2},{"Mary", 4} }), Step2 = Table.Skip(Step1,1) ...
- 1 year ago
let steps = [ Step1 = #table (type table[Names = Text.Type, Money = Int64.Type], {{"John", 1}, {"Jack", 2},{"Mary", 4} }), Step2 = Table.Skip(Step1,1) ], money_evolution = ((fields) => Record.FromList(List.Transform(fields, (x) => List.Sum(Record.Field(steps, x)[Money])), fields))(Record.FieldNames(steps)) in money_evolution
AlienSx
1 year agoSuper User
let
steps =
[
Step1 = #table (type table[Names = Text.Type, Money = Int64.Type], {{"John", 1}, {"Jack", 2},{"Mary", 4} }),
Step2 = Table.Skip(Step1,1)
],
money_evolution = ((fields) => Record.FromList(List.Transform(fields, (x) => List.Sum(Record.Field(steps, x)[Money])), fields))(Record.FieldNames(steps))
in
money_evolutionStefanoT1982
1 year agoRegular Visitor
that's great! would you mind explaining how it works? I'm little familiar with the "=>" function syntax
- AlienSx1 year agoSuper User
"steps" is record.
Record.FieldNames(steps)reads it's fields' names and gets list of names (of steps).
List.Transformgoes over the list, picks up every other (step) name and calculates List.Sum of Money column values.
Record.FromListfolds the results into another record with steps names and Money totals.
M is functional language so get used to functions syntax and usage.