This is kind of a complicated issue and I'm new to all of this, so hopefully it fits this forum.
Invoices are created and are related to contact information by a Contact ID. Each contact can have a credit limit that is stored in the contacts database. If the sum of the balance due for every invoice for that contact is > the credit limit, we want to halt the creation of a new invoice. The calculation is as follows:
Credit Limit Calc = If(Sum(Invoices::Balance Due) >Credit Limit , "No New Invoices!", "")
The problem I have occurs when trying to create a new invoice for a dealer that has a large number of older invoices. The calculation of the balance due can take a very very long time due to calculation of all invoice line items, etc...
What we would like to do is limit this calculation to only the last 5 or 10 invoices for that contact so that the time is reduced. I had some ideas, but the following seems to make it difficult:
-the invoices for a certain contact are not necessarily in numeric order at all
I can't figure out how to make a script or calculation that only considers the last five or last ten invoices (by date).
Any insight or help would be greatly appreciated.