Jump to content
Changes to the Jaspersoft community edition download ×

Sum of return values from subreports

Recommended Posts

By: Raju - rajum

Sum of return values from subreports

2006-03-08 08:54


My main report contains two subreports (in detail section). Each subreport returns a value.


For each row returned in the main sql query, the subreports need to be called.


I have two variables (Say x1, y1) with calculation="System" to store the values returned from subreports.


I created another variable with calculation="Sum" and variable expression as $V{x1} + $V{y1}. Something seems wrong here. It returns me wrong result.


Can anyone help me how do I sum all the return values from subreports?


May be a pseudo code can help understand my problem better


for each rowi returned in sql query


xi = subreport1(...);

yi = subreport2(...);


display ( x1 + y1 + x2 + y2 + .....);


Thank you for your time





By: Lucian Chirita - lucianc

RE: Sum of return values from subreports

2006-03-09 00:36



The cause of the miscalculation is that x1 and y1 have their value set in the course of the detail band's printing (as soon as a subreport ends), while the sum variable has its value incremented at the beginning of the detail band printing (at which moment x1 and y1 are not set).


The straightforward way to sum values returned from a subreport is to set calculation="Sum" to the returnValue element. You can then simply sum the variables for the two subreports:

for each rowi returned in sql query


x += subreport1(...);

y += subreport2(...);


display ( x + y );






By: Raju - rajum

RE: Sum of return values from subreports

2006-03-09 08:40

Thank you for the tip. It works just as expected.




Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...