Navigation:  Contents > Calculation of totals >

StimulReport.Net User Manual

Print this Topic Previous pageReturn to chapter overviewNext page

Expressions with aggregate functions

Expressions with aggregate functions are used only in the Text expression, Text component or the SystemText component. To sum up all values of one column you suffice to write in the text expression as follows:

 

 

{Sum(DataSource.Column)}

 

 

Also you may use combine expressions:

 

 

{100 + Sum(DataSource.Column) * 2}

 

Important! Do not use synchronously more than one aggregate functions in the text expression. In this case StimulReport.Net cannot make calculations correct. But if, nevertheless, you need to do it we recommend you using events of components for calculation of totals.

For example, you want to calculate the number of strings and sum up expression values. For this you should add the Footer band to a report. In this band you must put two Text components In the first component you should specify:

 

 

{Count()}

 

 

- in this component there will be the number of strings output.

In the second component you should specify:

 

 

{Sum(Products.UnitsInStock)}

 

 

- in this component there will be the number of values from the UnitsInStock column output.

 

The example of a report using aggregate functions.

 

As evident from the sample for calculation of number of strings of the Count function there is no need in additional arguments. One argument has been specified to the Sum function. It is the expression that should be summed up. In other words the report generator has specified to which Data band all these aggregate functions belong to and how many times these functions must be called.

 

Rendered report with two totals in the list.

 

This occurred because text components, in which aggregate functions had been used, were placed on the total Footer band. This band belongs to a Data band. This enables the report generator to bind the aggregate functions and the Data band automatically.

There are several types of total bands in StimulReport.Net. They are as follow:

 

ReportSummaryBand - this band is used for totals output of a report on the whole;
PageFooterBand - this band is used for totals output of a page;
FooterBand - this band is used for totals output of a list;
GroupFooterBand - this band is used for totals output of a group.

Placing components and aggregate functions together allows the report generator to indicate to which Data band do these aggregate functions belong. Also, in addition, you can put the component with aggregate function on the Data band. In this case there will be an output of the result of an aggregate function calculation of all strings.

Notice. In most cases StimulReport.Net automatically binds the aggregate function and the Data band together.