Forum Discussion
DSR
Resolver I
1 year agoList.Generate to calculate column based on the previous row value of the Same Column
There is no solution yet as of Sunday February 16, 2025, 7:00pm USA Eastern Time. Hello, Please your help is appreciated. Kindly in each line of the List.Generate write its clarification in deta...
dufoq3
Community Champion
1 year agoHi DSR, check this:
Output
let
Source = Table.FromRows( {
{"A", 0, "Yr00", 0, 2, 0, 0},
{"A", 1, "Yr01", 0, 2, 1, 1},
{"A", 2, "Yr02", 1, 2, 2, 1},
{"A", 3, "Yr03", 1, 2, 3, 1},
{"A", 4, "Yr04", 1, 2, 4, 0},
{"A", 5, "Yr05", 0, 2, 5, 1},
{"A", 6, "Yr06", 1, 2, 6, 0},
{"A", 7, "Yr07", 0, 2, 7, 0},
{"A", 8, "Yr08", 0, 2, 8, 0},
{"A", 9, "Yr09", 0, 2, 9, 0},
{"A", 10, "Yr10", 0, 2, 10, 0} },
{"Case.CC.EEName", "PeriodNo", "Yr", "NoEE.inPrvPrd", "Yr Move Out", "Index.inGrp", "NoEE"} ),
L = List.Buffer(Table.ToRows(Table.SelectColumns(Source,{"NoEE", "Index.inGrp", "Yr Move Out"}))),
Gen = List.Skip(List.Generate(
()=> [ x = -1],
each [x] < List.Count(L),
each [ x = [x]+1, y = L{x},
z = if (y{0}??0) = 0 then null
else if (y{1}??0) = 0 then null
else if ([z]??0) = 0 then 1
else if [z] = y{2} then y{0}
else [z] +1 ],
each [z] )),
Merged = Table.FromColumns(Table.ToColumns(Source) & {Gen}, Value.Type(Table.FirstN(Source, 0) & #table(type table[Answer=Int64.Type], {})))
in
Merged