Total associated with the band

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.

 Column. Totals are calculated for all columns in the report.

 page. Totals are calculated on all pages of the rendered report. 

 running total parameters. If this flag is checked, totals are calculated as running. If not checked, the totals will be calculated only for the project (reports, columns, pages).

 Condition parameter. If this flag is checked, the condition is taken into account when calculating the total. If not checked, the total will be calculated without considering the conditions.

 The field specifies an expression for the condition.

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. 
functionreturn type
sum()Decimal number
SumD()double
SumI()Int64
Note: The letters I, D can be added to all functions except Count and CountDistinct. These functions always return an Int64 type.

A few words about function syntax

When using the C# programming language, all functions must be written strictly conforming to registers.

 Sum (Formula) − The sum is calculated by automatically identified objects.

 Sum(band, expression) - Sum is calculated by a specific object.

 SumIf(band, expression, condition) - Sum is calculated by an object with a condition.

 Formula − Formula for calculation.

 band - the name of the band on which to perform the calculation.

 Condition − Condition to include the calculation in the formula.

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.

 cSum (formula) - calculation of sum by page or container.

 cSum(band, expression) - calculation of sum by page or container and objects on it.

 cSumIf(band, expression, condition) - calculation of sum by page or container and objects on it under certain conditions.

To calculate the sum per column, add the col prefix to the function name.

 colSum (expression) − The sum is calculated by columns.

 colSum(band, expression) - The sum is calculated by the column and the objects within it.

 colSumIf(band, expression, condition) - The sum is calculated by the column and the objects within it under certain conditions.

The Count function differs from other functions in that it has no formula for calculation. The syntax for this function is shown below.

 Count() - Calculates the number of rows.

 CountIf(condition) - Calculate the number of rows by a condition.

 Count(band) - Calculates the number of rows per object.

 CountIf(band, condition) - Calculate number of rows by object and condition.

 cCount() - Calculates the number of rows per page and container.

 cCount (band) - Calculates the number of rows per page (container) and objects on it.

 cCountIf(band, condition) - Calculates the number of rows by page (container) and objects on it under certain conditions.

 colCount() - Calculates the number of rows per column.

 colCount(band) - Calculates the number of rows by column and objects in this column.

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.

 ReportSummaryBand- The band is used to display totals for the entire report.

 PageFooterBand- The band is used to display totals per page.

 FooterBand- Band is used to display totals per list.

 GroupFooterBand- Band is used to display totals per group.

  ColumnFooterBand- Band is used to display totals per column.

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.

 Note: Components containing functions can be placed anywhere on 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.

{Total(DataBand1, Products.UnitsInStock)}. In this case, the sum of the Products.UnitsInStock column values for each row in DataBand1 is calculated.

{count(DataBand1)}. In this case the number of rows in DataBand1 is 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.

Note: If a component with this function is associated with a band with data bands, the report generator can determine the relationship between the function and a specific data band. In other words, the components with functions are in the header and footer bands related to this data band.

Otherwise, the argument should specify the data source or data band for which the sum should be calculated. In the expression, you can specify:

  Object where value is calculated - {Sum(DataSource.Column)}

  Objects and various math operations with them - {100+Sum(DataSource.Column)*2}

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.

 {AcCount(DataBand1)} - Report engine calculates the number of rows in one page or panel.

 Note: Calculating totals by page is the same principle as for panels.

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:

 {CountIf(DataBand1, Products.UnitsInStock = 0)} - The reporting engine will calculate the number of items equal to zero on this page.

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:

 {ColCount()} - The reporting engine will calculate the number of rows for each column.

Note: There is one limitation in calculating totals by columns in StimulsoftReports. Totals can only be calculated by page columns. Calculating totals by columns in the data band is not allowed.

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:

 {ColCountIf(DataBand1, Products.UnitsInStock = 0)} - The reporting engine will calculate the number of rows for each column where the condition is executed.

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.

Note: Do not use variables declared in your code to store the results of function calculations. You should use variables from the data dictionary.

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:

 variable += Products.ItemsInStock;

To display the calculated result, you need to position the text component using the following formula:

 {variable}

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.

{SumIf(Products.UnitsInStock, Products.UnitsInStock > 1)}. In this case the amount of the Products.UnitsInStock value is calculated. This is a value greater than 1.

{CountIf(Products.UnitsInStock == 0)}. In this case the number of rows with zero column values UnitsInStock

 Note: When doing calculations with Double or Int64, you must first add the Latin letter D or I before adding the word If. Example: {SumDIf(Products.UnitsInStock, Products.UnitsInStock > 0)}.

Automatic resizing of totals and components

 Note: At the moment when the report is rendered, the calculation result of the sum function is still unknown when the size of the component is determined. This should be taken into account when installing auto-sizing for components where totals are calculated. Otherwise, you may run into problems if the components are sized incorrectly for the result of the sum function.

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.