Aggregate functions can be calculated across the entire data source, a band, a group, or a page. When calculating an aggregate function by page, in some cases the result may be incorrect. In this article, we describe the reasons for such errors and the ways to resolve them. For simplicity, in the explanation below we will refer only to the Sum function, but the same logic applies to all aggregate functions.

The process of summing values by page

Summing values by report page occurs only after the report has been fully generated, so the result should normally be accurate. However, the report engine doesn’t sum values from text components, since these usually contain already rounded numbers. Instead, the engine scans the page for all rendered data bands. Each data band stores the position of the data source at the moment of its rendering, and the engine sums exactly the original values from the data source.

Why calculation errors occur

If the CanBreak=false property is set for a Data Band, then each row of the data band is rendered as a whole container, which can’t be split across pages. If it doesn’t fit on the current page, it is moved entirely to the next page. In this case, each row of the data band exists only once, and all calculations are accurate.

However, if the CanBreak=true property is set, then a data band row that doesn’t fit entirely on the page can be split into parts. One part of the band remains on the current page, while the other is moved to the next page. Components of this band, depending on their size and placement, may also end up split between parts. Moreover, if these components also have CanBreak=true, they themselves can be divided.

This raises the question: if a textbox is split into parts, on which page should its value be counted?

Our team tried to design a smart algorithm to handle such cases. However, since our product allows creating reports with extremely complex structures, it’s simply impossible to cover every scenario. Therefore, a decision was made long ago to follow these rules:

  • If after splitting a band, at least one component remains in the first part (i.e., at the bottom of the page), then its value is counted only on that page;
  • If all components of the band are moved to the top of the next page, then its value is counted only on the next page.

In most cases, this approach works correctly.

Example of a problem

Let’s consider a specific case of how values from text components are counted when summing by page.

Initial conditions: Data Bands have CanBreak=true, meaning their contents can be split. All text components on the band have CanShrink=true. This means that text components without data collapse and have zero height.

When the band is split, these empty text components remain on the previous page, while all components with data are moved to the next page. As a result, the first part of the band is not empty, and therefore the value from this band is counted only on the previous page.

Possible solutions

The simplest way: set CanBreak=falsе for the Data Band. This will both solve the summation error and speed up report generation.

If CanBreak can’t be disabled for some reason, you can set GrowToHeight=true for text components.

In general, it is recommended to apply both solutions, since enabling GrowToHeight also helps to avoid some issues during subsequent exports.
By using this website, you agree to the use of cookies for analytics and personalized content. Cookies store useful information on your computer to help us improve efficiency and usability. For more information, please read the privacy policy and cookie policy.