Jump to content

Variable in group is missing last detail record


rlfisherpbtgroup.com

Recommended Posts

Hello -

I have built quite a few reports, so I know that I am missing something obvious.  I have a subreport that renders in the detail band and returns a value to my main report.  That value is stored in a variable - calculation type=sum.  In a group footer I render that variable as a subtotal, and the variable resets for the next group.  Normal - I have done this in many reports.

This time, however, each subtotal is missing the last row that shows in the detail band, and includes its value in the NEXT group summation.

Normally, I would use evaluation time=now but I have also tried BAND and GROUP with the same results.  What am I missing?

Thank you in advance for any help

Link to comment
Share on other sites

  • Replies 9
  • Created
  • Last Reply

Top Posters In This Topic

Using a variable with values returned from a subreport in another variable's expression does not work (properly).  That's a limitation of JR; we'll try to address it sometime.

What you need to do is to sum the values when they are returned from the subreport.  See below for an example.

Regards,

Lucian

Code:
<variable name="subTotal" class="java.lang.Integer" calculation="System" resetType="Group" resetGroup="MyGroup"/><subreport>	<returnValue subreportVariable="var" toVariable="subTotal" calculation="Sum"/> </subreport>
Link to comment
Share on other sites

Thanks again for your kind reply. I have had no problem with variables/subtotals-in-bands in normal reports (subreports).

 

In this case (simplified) my main report queries a database for a series of organizations and the state (of the United States) to which they belong. The detail band for this query calls a subreport (passing district-identifying information, including database name) to get some information for this organization because (for historical reasons) each organization has their own database. The subreport renders one row of information for each district, and passes back two total numbers.

 

The intent is for the main report to accumulate these two totals and print them in a group footer each time the State (of the United States) changes. There is no problem doing this, of course, when a subreport is not involved. The quirk here is that each call to the subreport specifies a different $P!{databasename} - so I do not think there is anyway to do this without a subreport. MySQL v5, by the way.

 

Thank you again for your help.

Link to comment
Share on other sites

Ah... I didn't look at your suggestion closely enough, I see now that it is in the main (calling) report. To what Group does the <variable> reset? do I create a dummy group that changes on each call to the subreport?

 

FYI... what I have had until now is:

<variable name="total_student_time" class="java.math.BigDecimal" resetType="Report" calculation="System">

</variable>

 

<returnValue subreportVariable="total_student_time" toVariable="total_student_time"/>

 

Link to comment
Share on other sites

Thank you so much, Lucian.

I changed the returnvalue to calculation=Sum and the corresponding variable to reset on the group and those subtotals now work! I gather that we are essentially doing the summing in the returnvalue rather than it's destination variable.

Now I need to get the grand total (some of the subtotals) to work properly. Sum of the destination variables is overcounting. I need duplicated the returnvalue entry, and have it point to a non-resetting-on-group variable, but this approach for a grand total returns zero.  I should mention that the grand total is in the summary band.



Post Edited by rlfisher at 01/06/2010 19:34
Link to comment
Share on other sites

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...