If a formula isn’t returning the expected results, there is a good chance it’s because of when the formula is being evaluated. If you are trying to debug a formula, then you have to take many things into consideration: does the formula only use variables; should the formula be put in a different section; is the formula being evaluated while reading records or while printing records; does the report use a grouping section that may be effecting the order of evaluation. This is a lot to think about. You can cut down on the amount of time spent debugging formulas if you start out by following some general guidelines. The remainder of this section gives guidelines and examples for you to think about when writing your formulas.
Place formulas that reset variables to their default value in the Report Header or Group Header section. This insures that they are called before the formulas in the detail section are evaluated.
Be careful when using formulas that only have variables in them without any database fields. They will only get calculated one time prior to reading the records. If the formula is cumulative in nature, you need to force the evaluation time to be WhileReadingRecords. If the report uses groups then you should use the WhilePrintingRecords keyword.
The keyword BeforeReadingRecords can’t be used with formulas that have database fields or grouping/summary fields in them.
When you place multiple formulas within the same section, you can’t assume the order that they are executed in. If you need one formula to be evaluated before another formula (its result is used in other formulas) then put the EvaluateAfter keyword in the dependent formula. The following example shows how this is used. This formula relies upon the formula ParseName to take the {Customer.Name} field and parse the first name and last name out of it. The values are put into the global variables FirstName and LastName. This example formula returns the LastName variable so that it can be displayed on the report. The @ParseName formula isn’t shown here.
EvaluateAfter({@ParseName})
Global LastName As String
Formula = LastName
Summary calculations are performed while printing records. They can only do calculations on formulas that were evaluated beforehand (i.e. while reading records). Thus, a formula that uses WhilePrintingRecords can’t have summary functions performed on it.
Of course, these guidelines won’t be able to prevent every problem from happening, but they are here to help give you a start in the right direction.