rlfisherpbtgroup.com Posted December 29, 2009 Share Posted December 29, 2009 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 More sharing options...
lucianc Posted December 30, 2009 Share Posted December 30, 2009 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,LucianCode:<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 More sharing options...
rlfisherpbtgroup.com Posted December 30, 2009 Author Share Posted December 30, 2009 Thank you for your kind reply. In this case, each execution of the subreport references a different database, so I cannot accumulate the subtotal in the subreport, either. Link to comment Share on other sites More sharing options...
lucianc Posted December 30, 2009 Share Posted December 30, 2009 I don't get what the problem is. Could you ellaborate? What exactly are not able to do? Link to comment Share on other sites More sharing options...
rlfisherpbtgroup.com Posted December 30, 2009 Author Share Posted December 30, 2009 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 More sharing options...
lucianc Posted January 5, 2010 Share Posted January 5, 2010 The solution that I've describe above is not affected by the fact that subreports use different connections. Have you tried it?Regards,Lucian Link to comment Share on other sites More sharing options...
rlfisherpbtgroup.com Posted January 5, 2010 Author Share Posted January 5, 2010 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 More sharing options...
lucianc Posted January 6, 2010 Share Posted January 6, 2010 You mentiond in your initial message that you want to display the variable in a group footer. That's the group that you need to use as reset group.Regards,Lucian Link to comment Share on other sites More sharing options...
rlfisherpbtgroup.com Posted January 6, 2010 Author Share Posted January 6, 2010 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 More sharing options...
rlfisherpbtgroup.com Posted January 6, 2010 Author Share Posted January 6, 2010 I have it working now.For the subtotals... the return value is calculation=Sum and the corresponding variable is reset on the group.for the grandtotal... a second variable is linked to the return value but with reset=Report. Lucian thank you so much for your helpful suggestions. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now