Summaries are a special kind of formulas that are built into JReport to save you time and effort. They can be used to generate aggregations for your data using aggregate functions such as Count, Average, Sum, and Standard Deviation. Summaries work based on how your data is grouped. For example, if you group your data according to country, and you have two groups (US and Canada), then when you add a summary to the country group, you will get the summary result for each group. The aggregation objects in a business view function the same as summaries.
This chapter introduces creating summaries in a catalog. In a report that uses business view as the data source, you can also create dynamic aggregations to use in the report specifically.
See also Summary Fields for how to work with summaries as component in a report.
The aggregate functions JReport supports for computing data are generally divided into two types: normal functions and running functions.
A normal function calculates all records and returns only one fixed value that is reset to 0 for each group.
A running function calculates a value on each record and does not reset to 0 for each group. It is like the total sum of money for each transaction that is recorded on your checkbook. Each time you deposit or withdraw money from the bank, the record will compute the total of your checking account balance. Running functions when applied in crosstabs only work on columns.




You can predefine summaries in a catalog so as to use them directly in reports.
The New Summary dialog appears.

next to Summary On.
next to Group By. If the field you select is of Numeric/String/Date/Time type, you can further specify to which level data will be grouped by selecting a special function from the Special Function drop-down list. If Customize is selected, you can set the function by yourself in the Customized Function dialog.A static summary defined with a group-by field can only be used in a group with exactly the same group-by field. It will be invalid anywhere else. If no group-by field is added for a static summary, the summary can be used to calculate data based on the whole dataset a data component uses. For example, if your data component is grouped by 3 groups, you would need 4 static summaries, one for each group plus one for the final total.
Normally you want to display the value of the group where you use the summary so leave the value 0. For example, if you select Up or Down and input 0 in the combo box and insert this summary into any group, the summary will take effect on this group; if you select Up and input 1 and insert this summary to a group, the summary will take effect on the group higher than the group where the summary is inserted, and if you specify Down and 1, it will take effect on the lower group.
The advantage of dynamic summaries is you can create one summary and use it on every group level. Using the example above with 3 groups and a final total, you still only need one dynamic summary instead of 4 static summaries since the dynamic summary can be used for each group and for the final total. Using dynamic summaries will enable you to keep a much cleaner catalog without hundreds of static summaries that can only be used in one report at one level.
Besides predefining summaries in a catalog via the Catalog Manager, JReport Designer also provides you quick access to create summaries in a catalog from the UI where a summary list is provided, for example in the Resources box of the report wizard. In this summary list, the <New Summary...> item is available on the top. By clicking the item, you can create any summaries you want with the New Summary dialog, which are then added into the current catalog.
Summaries will also be created automatically in a catalog when you add summaries for each group while creating a query based table or banded object with the report wizard. However all summaries created automatically by the report wizard are static summaries, so when you use the report wizard to create a lot of reports in your catalog it will become very messy with many duplicate summaries. Therefore it is better to create dynamic summaries in the catalog and add them to the data components in your reports after you generate the data components with the wizards.