BackPrevious Topic   Next TopicNext

Formula Levels

Report categorizes formulas into six levels. These levels determine when Report Engine executes the actual statements in your formulas. This topic introduces the Report formula levels in detail.

Select the following links to view the different formula levels:

Note icon Report Engine makes several passes over the data to determine when it executes formulas. Even though an individual formula appears to be a certain level, if it references anything in the higher level, it also becomes the higher level formula.

Constant Level Formulas

A constant level formula is a formula that does not refer to any DBFields, summaries, global variables, page level special fields (the value of the special field is ready at the time when Report Engine generates the report), or other non-constant formulas. For example, return CurrentDate() is a constant level formula.

Report Engine executes constant level formulas before fetching data from the dataset, so if you place a constant level formula in the report header, Report Engine executes it immediately as it encounters the formula.

Back to top

Record Level Pass One Formulas

A formula is a record level pass one formula if and only if the following are true:

  • Refers to a DBField or any other formula which references a DBField.
  • Does not refer to any page level special fields or formulas which refer to page level special fields.
  • Does not refer to any global variable or any record level pass two formulas
  • Does not refer to a summary field.

Back to top

Record Level Pass Two Formulas

A formula is a record level pass two formula if and only if the following are true:

  • Refers to a DBField and a summary.
  • Refers to any other record level pass two formula.

Report Engine executes record level pass two formulas on each record of the dataset but only after the data has been grouped. For example, if you place a record level pass two formula in the banded header, the group is the entire report; if you place the formula in a group header such as Category, it is the value after all of the detail rows have been processed for the group. For example, you may want to display in a group footer the group name and total such as return "Total for " + @CATEGORY + ": " + @Sum_Total;.

Back to top

Group Level Formulas

A formula is a group level formula when it refers to only summaries or other group level formulas. For example, you have two summaries, Sum_Total and Count_Detail, you could write a group level formula as: return @Sum_Total / @Count_Detail, to display the average total sales on each line of the order.

Report Engine executes group level formulas when breaking the group on which you define the summaries, which could be a group or the entire report for a report level summary in the banded header or banded footer.

Back to top

Report Global and Global Formulas

If a formula refers to a global variable or report global variable and does not refer to any page level special fields, there are several rules for when Report Engine calculates the formula.

  • If you place the formula in the report header or group header, Report Engine calculates it when the group starts.
  • If you place the formula in the page header, page footer, or detail panel, Report Engine calculates it on each record after the data has been grouped the same as record level pass two formulas.
  • If you place the formula in the report footer or group footer, Report Engine calculates it when the group or report ends.

Report Engine calculates report global and global formulas based on all records of the group or report. For example, if you calculate an accumulated total that you display in a report footer or group footer, it works as expected. For example, you may want to calculate a total margin such as:

global number GrossProfit = 0;
GrossProfit = GrossProfit + (@Price - @Cost);
return GrossProfit;

However, if you show a running total in the detail, you see the group or report total on every line rather than the expected running total. The solution is to convert the formula to a page level formula by adding a reference to any page level special fields.

Note icon You can use report global and global variables only in page reports.

Back to top

Page Level Formulas

Report converts all the other formula types to a page level formula when the formula calls next(), prev(), IsNoRecord(), or references any of the page level special fields.

Report Engine calculates page level formulas in the exact sequence of the panels as they display. Thus, if a page level formula includes any of the page level special fields, Report Engine calculates it in the detail or group header and footer exactly in the order they are laid out. In the preceding example, if you want to do a running total on each detail, the formula expression is:

PageNumber;
global number GrossProfit = 0;
PageNumber;
GrossProfit = GrossProfit + (@Price - @Cost);
return GrossProfit;

PageNumber also controls the sequence of calculations around page breaks. When a formulas references PageNumber, Report Engine performs the calculation before the page break; otherwise, it performs the calculation after the page break. This is important when you use formulas to control properties.

Back to top

BackPrevious Topic  Next TopicNext