# Finding records to reach a certain total

**URL:** <https://the.fmsoup.org/t/finding-records-to-reach-a-certain-total/3552>\
**Category:** Questions\
**Tags:** filemaker\
**Created:** [May 8, 2023, 10:07pm UTC](https://the.fmsoup.org/t/finding-records-to-reach-a-certain-total/3552 "2023-05-08T22:07:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![VernK](https://avatars.discourse-cdn.com/v4/letter/v/e56c9b/32.png) [@VernK](https://the.fmsoup.org/u/VernK)\
**Post date:** [May 8, 2023, 10:07pm UTC](https://the.fmsoup.org/t/finding-records-to-reach-a-certain-total/3552/1 "2023-05-08T22:07:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Torsten](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/torsten/32/1574_2.png) [@Torsten](https://the.fmsoup.org/u/Torsten)\
**Post date:** [May 9, 2023, 2:08am UTC](https://the.fmsoup.org/t/finding-records-to-reach-a-certain-total/3552/2 "2023-05-09T02:08:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![menno](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/menno/32/2016_2.png) [@menno](https://the.fmsoup.org/u/menno)\
**Post date:** [May 9, 2023, 9:48am UTC](https://the.fmsoup.org/t/finding-records-to-reach-a-certain-total/3552/3 "2023-05-09T09:48:03Z")

</div>

> [@VernK](#):
>
> going backwards from the current record **where** the total of _corner increment_ is equal to or more than the global value

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](https://the.fmsoup.org/uploads/short-url/n1IVO29g1c3bmPkVQOiw6VaLCi6.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 \*/  
> )

---

<div class="post-metadata">

**Author:** ![VernK](https://avatars.discourse-cdn.com/v4/letter/v/e56c9b/32.png) [@VernK](https://the.fmsoup.org/u/VernK)\
**Post date:** [May 9, 2023, 3:23pm UTC](https://the.fmsoup.org/t/finding-records-to-reach-a-certain-total/3552/4 "2023-05-09T15:23:46Z")

</div>

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

Thanks, I will try it out & report back.

Yours  
Vern
