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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculate sum of fields 1

Status
Not open for further replies.

maas

Programmer
Sep 3, 2009
148
BH
Hello All,

I am having difficulties while calculating the sum of the a field.

My report structure is:

Group Header 1#: Account Name
Group Header 2:# ACC_groups
Details: Deal_No, Amount
Group Footer 2#: Sum (Deal.Amount), Account Groups
Group Footer 1#: Sum (Deal.Amount), Account_Name

For the total I have implemented teh below formulas:

{@reset} in Group Header 1
whileprintingrecords;
numbervar sumpct;
numbervar grtotal;
if not inrepeatedgroupheader then (
sumpct := 0;
grtotal := 0
);

{@accum}
whileprintingrecords;
numbervar sumpct := sumpct + (Deal.Amount);
numbervar grtotal := grtotal + (Deal.Amount);

{@displaygrp} to be placed in the GF#1:
whileprintingrecords;
numbervar sumpct;

{@displaygt}
whileprintingrecords;
numbervar grtotal;

Now the problem is while displaying the sum in Group Footer 2: (EX:
G1-Header:MM100
G2-Header:123
Details:555 , 10000
556, 20000
G2-Footer Total: 30000
G2-Header: 233
557, 500
Total: 305000 ( instead of this figure, I want the 500)
Grand Total 305000

I tried to use the insert summary , but I can't get the correct figures because I am doing group selection:

{GL.GL_ENTRY_ID}= maximum ({GL.GL_ENTRY_ID},{Deal.DEAL_NO})

So, what should I modify in the previous formulas to get the 500 for the sum of the group instead of getting the sum of the whole amount?

Thanks
 
One more thing is that the total is in group footer 2
 
YOu need to move the reset of variable sumpct into GH2, just create formula reset2

whileprintingrecords;
numbervar sumpct;
if not inrepeatedgroupheader then (
sumpct := 0;

Ian
 
maas,

You really must stay with one thread, instead of starting multiple threads on the same topic. I may have given you the incorrect instruction in your last thread, but you should have responded with your incorrect results, and I would caught my own mistake at that point.

What you need to understand is that the reset formula and the display formula for the same variable must be in the corresponding group, so if you want a result at the group footer 2 level, you need a reset in the group header 2. This means that you will have separate reset formulas if you are also using a separate variable for a group #1 result.

Another approach would have been just to add a running total that resets on change of Group #2. A running total will automatically honor the criteria in the group selection formula.

-LB
 
Thanks to all of you.

lbass Thanks for your notice.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top