To calculate and display the total, place a text component inside the report, invoke the editor and go to the "Summary" tab.
expression field. This field specifies the formula that calculates the sum. Expressions can be specified manually or automatically generated by other parameter types.
Summary function field. In this field, the function that calculates the sum is selected.
This field allows you to specify the data bands for which the sum will be calculated.
This field allows you to specify in the data column which values to use to calculate the sum.
You can use the radio buttons to set what you want to calculate the total for.
report. Totals are calculated for the entire report.
of the sum of the function resultstype
By default, functions that compute the sum return Decimal type (except functions - Count and CountDistinct). But you can also do calculations with two other data types, Double and Int64. For functions that return computed results using the Double data type, prepend the Latin letter D to the function name. Calculations using the Int64 type require the Latin letter I to be added to the high register. This separation avoids losses in calculating the sum. |
function | return type |
sum() | Decimal number |
SumD() | double |
SumI() | Int64 |
A few words about function syntax
When using the C# programming language, all functions must be written strictly conforming to registers.
For calculations by page or container, the syntax is the same, but with the Latin letter c added as a prefix to the function name.
To calculate the sum per column, add the col prefix to the function name.
The Count function differs from other functions in that it has no formula for calculation. The syntax for this function is shown below.
Show totals anywhere
Normally, text expression components with function calls are placed in the footer band of the data band. There are several types of footer bands.
The location of the component with any of the above band functions allows the report generator to determine exactly which data band this function is applicable to. You can also put a component with functionality in the databand. In this case, each data row will display the function calculation results for all rows.
For example, if you want to display a total in the header band, do this with a script. However, in Stimulsoft reports, components with functions can be included in any band of the report.
You can also place components containing functions on report template pages and other pages. For example, a list can calculate the sum of the values and output it to the header list. Another example is calculating the number of rows in a list and printing the value at the top of the page. At the same time, there are limitations. You have to specify the data band for which the result will be calculated.
Expressions using functions
To calculate the sum, the formula can have no additional arguments. For example, for the Count function, this is optional. Alternatively, the Sum function can have only one argument. This is the formula that needs to be calculated. All this is possible if the report generator can determine which data band these functions relate to.
Otherwise, the argument should specify the data source or data band for which the sum should be calculated. In the expression, you can specify:
Calculating totals per page
To calculate totals per page or panel, you must prefix the function name with the Latin letter 'c' in lower case.
When calculating totals on a panel or page, it is desirable to specify which data band to use for calculating aggregate functions. I need this because there can be multiple databands on one page.
Any number of aggregation functions can be used on a single page or panel. Stimulsoft software has no restrictions on this. You can combine page totals and conditions. for example:
Calculating totals by columns
To calculate the sum per column, you need to add a lowercase prefix col (from the word column) to the name of the function. for example:
If you want to calculate the sum per column, it is preferable to put the text component containing the function in the ColumnHeader, ColumnFooter, Header or Footer band. An unlimited number of totals can be calculated per column. There are no restrictions on this. You can also combine per-column footers with:
Calculate total in event code
Stimulsoft software allows you to compute functions in code for report events. Provides the ability to compute more complex functions. Also, in this case, during the course of the calculation, code can refer to the calculated value and influence this process. To do this calculation, we need to create a variable in the data dictionary to store the value of the function.
The data type of the variable is indicated when you create the variable. For example, Decimal, initial value, for example 0. Next, in the Data band, here's an expression that increments a variable on the Rendering event. For example, to calculate the sum of the values in the field Products.UnitPrice field, the formula would be:
To display the calculated result, you need to position the text component using the following formula:
I also need a text component for the expression {Variable}. Set the ProcessAt property to the End ofReport value. The report generator should calculate the value of the variable after processing the rest of the components.
Computing sums with conditions
Certain values may need to be considered when calculating the total. In this case, the condition is set with a function that calculates the sum. For example, I need to sum values greater than zero. To add a condition to the function that calculates the sum, we need to add the suffix If (Latin alphabet) to the function name and add the arguments to the condition.
|
Automatic resizing of totals and components
|
Total with data band disabled
Databand can be disabled in various ways. For example, it may be disabled under certain conditions or have a height of zero. By default, the report engine does not consider disabled databands and does not process them when rendering a report. However, if you need to calculate the sum for each disabled data band, you should set the CalcInvisible property of this band to true. In this case, the report will only show the bands that contain data, and the total calculation will be performed taking into account the data bands.
Calculating totals in master-detail reports
When calculating totals in hierarchical reports, there are some problems with calculating the results. Consider an example based on a master-detail report. Suppose your report displays a list of product categories. In this case the category is the master entry and the product is the detail entry.
Suppose you want to count the number of products displayed in a report. If you use the function Count() to add a footer band to the band containing the list of products (detail record), the total will be calculated for each category (master record).
If you use the function Count() to add a footer band to a band with categories, the result will be the number of master entries in the report, the number of categories. However, a master-detail report can immediately calculate totals for all detail records. In this case you have to specify the names of both (master and detail) bands as a function with a colon: Count(MasterBand:DetailBand).
The result of the Count(MasterBand:DetailBand) function is the number of products in all categories.