Forum Discussion
Data overflow error when the "List.Accumulate" function was used to process data over 2000 rows
- Anonymous6 years ago
Curt Hagenlocher's argument seems interesting to me.
<<...
But broadly speaking, M is a lazy language and some of the things you compute actually result in promises instead of immediate values. If the combination function passed to List.Accumulate results in a promise, then the result of accumulating over your list is a promise on top of a promise on top of... etc. At some point, when the actual value is calculated, it's done recursively -- the chain of promises is too long and the stack flows over.
>>
Iterating over a record with the List.Accumulate function usually doesn't go wrong, but it does when it comes to combining lists or tables etc.
In our PQ group, we usually only dare to use it to deal with some data under 2000 lines
with a Sorgn={1..1000000}, for example
comrec = List.Accumulate(Sorgn,[a=0],(s,c)=> s&[a=c]),
comrec=List.Accumulate(Sorgn,[acc=0,cur=0],(s,c)=> s&[acc=[acc]+c,cur=c]),
comrec=List.Accumulate(Sorgn,[acc=0,cur=0],(s,c)=> s&[acc=s[acc]+c,cur=c])
the first expression gives the result immediately;
the second quickly gives as a result a record with the field acc = error(*) and the field cur = 100000;
the third expression overflows
(*) the correct form is the third expression.