Calculation of totals in a code of report events
Using StimulReport.Net you may make calculation of aggregate functions in the code of events of a report. This allows to calculate aggregate functions with complex logic and condition. Another advantage of StimulReport.Net is that when report rendering you call the value to be calculated from the report code and make changes. If you want to make such a calculation the variable which stores the value of an aggregate function is required. For this you should create a new variable in the data dictionary.
Important! Usage of variables from the code to store the result of an aggregate function calculation is barred. You should use variables from the data dictionary.
The window to create a new variable.

Here you specify the type of a variable, e.g. Decimal, and the initial value equal in zero. Then from the Data band in the Render event you should set the code of a variable increment. For example, if you want to calculate the sum of variables of the Products.ItemsInStock field then the code will be as follows:
C#
MyTotals += Products.ItemsInStock;
VB
MyTotals = MyTotals + Products.ItemsInStock;
Addition of a code into the event for calculation of totals.

The RenderingEvent event
The Data band in which the RenderingEvent event the calculation will be made.
The code for calculation of a sum
For calling to the variable that contain the value of a total write in the text expression as follows:
{MyTotal}
If, after you have written the text expression, you run the report rendering. Then when the report rendering will reach the component which contains the expression with the total variable there will be an output of this variable. Therefore you should specify to the report generator that the component output must be done right after the whole report rendering - when the variable will be calculated completely. For this you must set the ProcessAtEnd property of the text component in True.
Notice. Expressions of text components which the ProcessAtEnd property is set in True are always being calculated at the end of the report rendering.
As was written before the total will be calculated and shown in the proper part of a report.
Rendered report with output of the total calculated in the code of the report.
