Finding records to reach a certain total

I have a set of records with a field (corner increment) containing an integer number, always positive and never zero. I need a script to find the set of records, going backwards from the current record where the total of corner increment is equal to or more than the global value in corner basket.

I think I’m asking for an iteration routine but I don't know much about those. Any help appreciated.

Yours
Vern

Welcome @VernK !
In a script, assign the value of ‘corner basket’ to a variable and use it in a Perform Find script step as a search criteria.

Do you mean until? Otherwise you could do a find as suggested by @Torsten

If you actually mean until then you may find use in this example:
Find previous records.fmp12 (384 KB)

The calculation is a while-loop:

While ( [
b = increment basket ;
i = corner increment ;
f = Get ( FoundCount ) ;
n = 0
] ;
b > i and
n < f
; [
n = n + 1 ;
i = i + GetNthRecord ( Record::corner increment ; f - n )
] ;
n /* + If ( n < f ; 1 ) / / add this in case the current record must be included */
)

I do mean until. And I think I almost understand the script.

Thanks, I will try it out & report back.

Yours
Vern