Forum Discussion
alex753
3 years agoFrequent Visitor
iterative/recursive calculations in Power Query or DAX
Hi, I'm a beginner and I'd like to know if it's possible to make certain iterative calculations. In my case I would like to be able to obtain a column that allows me to obtain a performance over my ...
AlienSx
3 years agoSuper User
Hello, alex753 either List.Generate
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
dv = Source[daily variation],
dv_count = List.Count(dv),
gen =
List.Generate(
() => [i = 0, result = 100 + dv{0}],
(x) => x[i] < dv_count,
(x) => [i = x[i] + 1, result = x[result] * (1 + dv{i})],
(x) => x[result]
),
result = Table.FromColumns(Table.ToColumns(Source) & {gen}, Table.ColumnNames(Source) & {"Result I want"})
in
result
or List.Accumulate
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
dv = Source[daily variation],
dvp = List.Skip(List.Positions(dv)),
acc =
List.Accumulate(
dvp,
{100 + dv{0}},
(s, c) => s & {List.Last(s) * (1 + dv{c})}
),
result = Table.FromColumns(Table.ToColumns(Source) & {acc}, Table.ColumnNames(Source) & {"Result I want"})
in
result
- alex7533 years agoFrequent Visitor
Thanks for you help, both solutions work well !