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

Sum Variable adding last amount twice in total in one group only 1

Status
Not open for further replies.

csesi

Technical User
Dec 14, 2011
5
US
I have a report grouped by the following:
Group #1 - Company
Group #2 - GLAcctNo
Group #3 - Contract
Detail - Contract lines

I am attempting to sum the Balance of each contract by GL Account, Company and Grand Total. Since these are formula fields, I am using shared variables.

The Totals for Company and Grand (report footer) are fine. However, the Total for the GLAcctNo is taking the last value in the list and adding it twice into the total.

GROUP HEADER #1 holds the reset for the total for Company
WhilePrintingRecords;
CurrencyVar EndBalSumCOID:=0

GROUP HEADER #2 holds the reset for the total for GLAcctNo
WhilePrintingRecords;
CurrencyVar EndBalSumGL:=0

DETAIL GROUP holds contract detail line information, including EndBalance of each contract line

GROUP FOOTER #3 holds the three calculation fields for EndBalance running total
WhilePrintingRecords;
CurrencyVar EndBalSumGL:=EndBalSumGL + {@EndBalance};

WhilePrintingRecords;
CurrencyVar EndBalSumCOID:=EndBalSumCOID + {@EndBalance};

WhilePrintingRecords;
CurrencyVar EndBalSumTotal:=EndBalSumTotal + {@EndBalance};

GROUP FOOTER #2 holds the sum by GLAcctNo
WhilePrintingRecords;
CurrencyVar EndBalSumGL:=EndBalSumGL + {@EndBalance};

GROUP FOOTER #1 holds the sum by Company
WhilePrintingRecords;
CurrencyVar EndBalSumCOID:=EndBalSumCOID + {@EndBalance};

REPORT FOOTER holds the Grand Total
WhilePrintingRecords;
CurrencyVar EndBalSumTotal:=EndBalSumTotal + {@EndBalance};

NOTE: I cannot use the Insert Subtotals because the EndBalance calculation is built off of subreport information.

When I run the report, I get the following example data:

GL #40000 Contract #0000000041 $41,414.13 (41,414.13 running)
Contract Total $82,828.26 (double the value)

GL #40050 Contract #0000000140 $39,405.00 (39,405.00 running)
GL #40050 Contract #0000000141 $ 2,000.00 (41,405.00 running)
Contract Total $43,405.00 (adding 2,000 in 2x)

Company Total $82,819.13 (correct)

Grand Total $82,819.13 (correct)

Please let me know if you need anything else to help.

~CS
 
Here is the principle you need to follow to address this. To display the result of a variable calculation, you must ONLY reference the variable in the footer, not add the same formula that does the calculation, since this will cause the variable to accumulate one more time. So the following formula:

GROUP FOOTER #1 holds the sum by Company
WhilePrintingRecords;
CurrencyVar EndBalSumCOID:=EndBalSumCOID + {@EndBalance};

...should instead be:

WhilePrintingRecords;
CurrencyVar EndBalSumCOID;

You should apply this principle to all display formulas.

-LB
 
Thank you, that worked. I'm self taught on Crystal going by what I've learned through these forums. Just because something has always worked in the past, doesn't mean that is the correct way to do it. I appreciate your guidance to the correct methods.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top