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 of Variable (again!)

Status
Not open for further replies.

pomster

Technical User
Jan 15, 2003
88
AU
My problem,
I have a report that is grouped by customer then by contract. I have a subreport in the contract footer that calculates revenue. I have succesfully passed a variable from subreport to main report {@RevenueSum} I need to sum this value by customer.

Sorry to be a pain but I have looked through this forum and tried a few alternatives but the only thing I can get to work is a separate subreport for total.

Thanks in advance,

David
 
David,

It isn't clear exactly what alternatives you have tried, but assuming you haven't given this approach a shot, the following should work:
Code:
//@Formula1
WhilePrintingRecords;
Shared NumberVar YourSubreportTotalVariable;
NumberVar CustomerRevenueTotal;

CustomerRevenueTotal := CustomerRevenueTotal + YourSubreportTotalVariable;

//@Formula2
WhilePrintingRecords;
NumberVar CustomerRevenueTotal;

//@Formula3
WhilePrintingRecords;
NumberVar CustomerRevenueTotal := 0;
Place {@Formula1} in your Contract Footer - after the section the subreport is placed in. i.e. If you only have on Contract Footer, split the footer into Contract Footer A and B, with the subreport occupying Footer A and {@Formula1} being placed in Footer B.

Suppress Footer B.

Place {@Formula2} in your Customer Footer, and {@Formula3} in your Customer Header.

Let us know how you get on.

Naith
 
Thanks Naith, Worked a treat. I'm still not completely confident with variables, but getting there!!

Regards,

David
 
Hi Naith,
I have similar problem like David, Currently I can't sum up my Shared Variable from my sub Report.
Eg:
Loc ProductID ProductName QtyReceive QtySales QtyBalance
A P001 Orange 10 5 5
A P002 Grapes 10 2 8
A P003 Apples 10 8 2
Sub Total 30 15 15

Loc ProductID ProductName QtyReceive QtySales QtyBalance
B P001 Orange 20 10 10
B P002 Grapes 20 4 16
B P003 Apples 20 16 4
Sub Total 60 30 30

All the Qty generated from subreport fomula:= share variable
And Retrieve from Main report. All the Qty taken are correct.
The Question are how to sum up all the Qty at the Sub Total? (red font)

Thank in advance.
awaysolution
 
I am presuming that your subreport ends after LocA, and then kicks off again for LocB. If this is the case, do the following:

In your subreport:

@Formula1
Shared NumberVar X := Sum({QtyReceive})

In your main report - in a section after the subreport:

@Formula2
Shared NumberVar X;

Repeat the same process for {QtySales}, and I guess subtract one formula from the other to get QtyBalance.

If your subreport executes once in order to display all the LocA and LocB information you've displayed, you will have to do your subtotalling in the subreport, as you can only pass the subtotal of your last group, or the grand total, to the subreport.

Naith
 
Hi Naith,
Thank Naith. Actually I need to summary after the subreport is executed. Eg: foreach record it will pass in the location, productId as a parameter to subreport and return me the quantity count. So foreach subreport only return me the quantity base on the location and productId.
Now I have to sum up the whole quantity (QtyReceive, QtySales and QtyBalance)

There is away to overcome this problem by creating 3 fomula at the Main Report

1) Init - create a variable and reset it to 0 at Header
NumberVar totalqty :=0;
2) Exec - sum up the variable record by record
totalqty := totalqty + qtyreceive;
3) Disp - Display the variabe that I create and put at the
footer.

For that I got all the quantity for each of the column
Anyway Thank you very much.

Regards,
awaysolution

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top