Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sum shared Variable on main report 1

Status
Not open for further replies.

Trainingjason

Instructor
Dec 6, 2001
127
GB
I have returned a shared variable to the main report, for each group. I am having difficulty adding up all the returned values in the groups.

My answers are simply copying the last shared value to the group, which is not what I want

Any help appreciated

trainingjason
 
After the subreport has fired, use a formula, as in:

whileprintingrecords;
shared numbervar RetValue1; // returned value
numbervar RetValue1Total:=RetValue1Total+RetValue1

-k
 
I have placed your formula in the main report, report footer, unfortunately it is copying the last shared value

Design of report is as follows

Main report

Group Header
CustomerID

Details
Subreport- linked on customer id.
Subreport is grouped and a shared variable is stored in the subreport group footer.

Group Footer
Shared variable is passed from the sub report to the main report

Main Report Footer
I can not add up the group totals based on the shared values passed through

I hope this helps

Jason
 
I think the subreport should go in group #1a footer, and the shared variable in group #1b footer, but I don't think this is the problem.

To get the grandtotal, create two formulas, where "amt" is your shared variable in the main report group footer:

{@accumgrandtotal} to be placed in the group footer:
whileprintingrecords;
shared numbervar amt;
numbervar grandtotal := grandtotal + amt;

{@displaygrandtotal} to be placed in the report footer:
whileprintingrecords;
numbervar grandtotal;

-LB
 
Right click the group that the subreport is in and select insert section below, place the formula there.

Now the grand total would be in the report footer, as in:

whileprintingrecords;
numbervar RetValue1Total

-k
 
I am using the xtreme database to practise hence I have the value of the grouped subreport passed to Group Footer Section A. when I placed the following formula in section B of the group footer to calculate, the result is wrong

whileprintingrecords;
shared currencyvar subReportV;
shared currencyvar Total:=total + subreportV

When using the SubReport for totaling orders.orderamount the value for the report is 4,124,721.17.

When creating a report on the orders table and calculating the grandtotal of the orders.orderamount the total is 4,083,665.34

Can anybody explain the difference I am using CR8.5.

Regards


Jason
 
It's hard to tell since you haven't provided much info, but if you are trying to get a total by placing the same formula that you are incrementing by in the report footer, it will increment again, which is why you need the separate display formula as in my suggestion above.

You also have to be careful about causing increments by inadvertently using two formulas that are incrementing the same global variables in the same section. This could happen when you are testing different formulas, so you should always remove previous test formulas from the report canvas.

-LB
 
follow lbass's advice:

{@accumgrandtotal} to be placed in the group footer:
whileprintingrecords;
shared numbervar amt;
numbervar grandtotal := grandtotal + amt;

{@displaygrandtotal} to be placed in the report footer:
whileprintingrecords;
numbervar grandtotal;
grandtotal;

IF this is not giving you the correct answer...then there is something wrong with your subreport. You can diagnose it a bit by displaying "amt" and "grandtotal" in the ClientID footer by modifying the formula and unsuppressing the formula:

{@accumgrandtotal} to be placed in the group footer:
whileprintingrecords;
shared numbervar amt;
numbervar grandtotal := grandtotal + amt;

"Amount: " + totext(amt,2) + " GrandTotal: " + totext(grandtotal ,2);

A guess of mine is that you are not resetting "amt" properly to zero before executing the subreport again...I would do this immediately after the calculation of the "grandtotal"

{@accumgrandtotal} to be placed in the group footer:
whileprintingrecords;
shared numbervar amt;
numbervar grandtotal := grandtotal + amt;
amt := 0;

now there would be no contamination




Jim Broadbent
 
Just a quick additional note. Hope it will be useful.

I was struggling with the same issue today too.

I used what Trainingjason and synapsevampire mentioned in this thread and I realized that if the total I declared was created by the running total in Field Explorer in subreport and picked up again in the main report in the group footer section, it will get the first record's vaule only of the group in subreport and sum them up.

However, if the total created is using the right-click (on top of the field for totaling) -> insert -> subtotal in report area of subreport (default position in CR), it will not have the strange accumulating problem.

Not sure how to explain in clearly, if some guru can, would like to know more.

anyway, my challange is over and now looking for more in CR!

 
Try a new post, old threads are often overlooked here.

As for your question, a Running Total isn't a shared variable, so the Running Total would have to be referenced in another formula using a shared variable to pass it.

The question didn't make much sense though, try a new posting with environment information, example data and expected output.

-k
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top