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 formula adds once too often

Status
Not open for further replies.

mdg123

Programmer
Sep 4, 2003
4
US
CR 8.5; SQL Server 2000
I have a report that prints out line items for an order: line number, item number, description, qty, and weight. Occasionally, there are detail comments that get associated with a line number/item. But the comments come in separate lines: line 2, item A, may have 3 SEPARATE detail comment lines attached to it. So I get duplicate lines printing. By watching the change of line number, and using the item to check the EOF, I can print the details only once, and capture all the comments.
Problem is summing the weights. Can’t underlay, or suppress, since it still sees the “hidden” weights when summing. The formula below captures the individual weights, but adds in the last weight once too often: the result is consistently over by the last item in the report:
So if I have:
Line Item Qty Wt
1 23 4 10
2 26 3 13
3 36 12 37
comment
comment
comment
4 18 2 12
TOTAL WT: 84 (instead of 72).

Code:
WhilePrintingRecords;
numberVar iWeight  ;
numberVar sumWeight;
iWeight :={t_item_master.unit_weight} * {t_hu_detail.planned_qty};	[COLOR=red]//Calcs Weight[/color red]
if not NextIsNull ({t_hu_detail.item_number}) then				[COLOR=red]// finds EOF[/color red]
(if{t_hu_detail.line_number} = Next ({t_hu_detail.line_number}) then	[COLOR=red]// chk for dupe[/color red]
iWeight := 0
else
iWeight);
sumWeight := sumWeight + iWeight;
iWeight;
Code:
WhilePrintingRecords;
numberVar sumWeight  ;
sumWeight;

Any suggestions as to how to get a correct total would be appreciated.
 
I mimicked your formulas and cannot recreate the problem, except by using your first formula in the report footer instead of the display formula (your second formula). This would cause one additional accumulation. So check for stray formulas in the report footer and make sure only the following one using the sumweight variable is there:

WhilePrintingRecords;
numberVar sumWeight;
sumWeight;

-LB
 
lbass:

Thanks: from your suggestion, and your response in thread767-880363
, I think I got it. I took the summing out of the first formula, created a formula just to sum the iWeight calc (in the detail), and gave that result to the formula in the footer. No more extra additions. Looks like I tried to do too much in the one formula.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top