Search code examples
jasper-reports

Jasper-reports: subtotal group new page


Can someone help me realizing the following in Jaspersoft studio.

My data is grouped. Now when the detail lines for a group goes beyond a page the total of all the lines belonging to that group must be shown on top of the following rows on the next page. So more schematically I’m trying to realize the following:

Page 1

Group A

Detail line 1 amount

Detail line 2 amount

Detail line 3 amount

Detail line 4 amount

Total for group A

Group B

Detail line 1 amount

Detail line 2 amount

Page 2

Total amount for group B on the previous page (line 1 and 2 in group B)

Detail line 3 amount

Detail line 4 amount

Total for group B

Thanks!


Solution

  • After a lot of searching, trail and error I came to the following solution.

    1. Place the fields in the relevant group header. Set the reprint header on each page to true.
    2. Create a variable with
      • calculation sum
      • expression: field you which to sum
      • initial value expression java.math.BigDecimal.ZERO
      • Increment type none
      • Increment factory class: (leave empty)
      • Reset type relevant group
    3. Add this variable to a text field with evaluation time now.

    Voila. Once again this solution seems to work but there was/is a lot of trail and error in finding a solution.