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

Sum of Group Totals

Status
Not open for further replies.

LZido

Technical User
Aug 24, 2006
21
US
I am trying to get a grand total for all groups.

I have groups with totals for items and totals for cost. I multiple the total items by their cost.

ITEM (each of these are groups) QNTY (this is a group summary) COST (@TotalCost)
Adult Cric Kit 2 $10.08
Ambu Bag Mask and Tubing, Adult 3 $26.31
Blade mac 2 1 $ 3.49
Blade mac 3 1 $ 3.49
Blade mil 2 4 $13.96


For this report
I created a formula to show cost for each item.

Formula Name: TotalCost2

if {UDF.Caption} = "Adult Cric Kit" then 5.04 else
if {UDF.Caption} = "Ambu Bag Mask and Tubing, Adult" then 8.77 else
if {UDF.Caption} = "Blade mac 2" then 3.49 else
if {UDF.Caption} = "Blade mac 3" then 3.49 else
if {UDF.Caption} = "Blade mac 4" then 3.49 else
if {UDF.Caption} = "Blade mil 0" then 3.40 else
if {UDF.Caption} = "Blade mil 1" then 3.49 else
if {UDF.Caption} = "Blade mil 2" then 3.49 else
if {UDF.Caption} = "Blade mil 3" then 3.49

I then multipled the cost by the sum of items in each group which returned a currency field (This formula is correct, returns the correct numbers)

Formula Name: TotalCost

{@TotalCost2} * Sum ({UDD.DataInt}, {UDF.Caption})


Next - I created a the following formula and placed in the report header

whileprintingrecords;
numbervar x;
if not inrepeatedgroupheader then
x := 0;

This next formula is where the problem lies -- it will not accept {@TotalCost} - it says "A number is required here"

whileprintingrecords;
numbervar x := x + x + {@TotalCost}


Formula placed in footer:

whileprintingrecords;
numbervar x;


Any ideas???
 
I'm not certain about this and I don't have Crystal in front of me to test my theory, but I have been caught out in the past using a NumberVar when dealing with currencies.

Given that {@TotalCost} appears to be a number (other than its formatting) I suspect this won't help but as a test, try changing the "x" from a NumberVar to a CurrencyVar (in both formulas).

Cheers
Pete
 
I'd take a different approach. Have formulas at detail-line level, which assigns the correct price to each product and then gives you the cost as price * items.

Price you already have, just make it a Formula Field, e.g.
Code:
if {UDF.Caption} = "Adult Cric Kit" then 5.04 else 
if {UDF.Caption} = "Ambu Bag Mask and Tubing, Adult" then 8.77 else
if {UDF.Caption} = "Blade mac 2" then 3.49 else 
if {UDF.Caption} = "Blade mac 3" then 3.49 else
if {UDF.Caption} = "Blade mac 4" then 3.49 else
if {UDF.Caption} = "Blade mil 0" then 3.40 else
if {UDF.Caption} = "Blade mil 1" then 3.49 else
if {UDF.Caption} = "Blade mil 2" then 3.49 else
if {UDF.Caption} = "Blade mil 3" then 3.49
else 0
Allow for unknown.

Then get the cost at detail line level
Code:
{UDD.DataInt} * @price

You could display this as a temporary display at detail line level to check all is well. Then right-click and Crystal will let you create summary totals at group level and report level, all automatically. No need to worry about data type.

The use of Crystal's automated totals is outlined at FAQ767-6524.

PS. It helps to give your Crystal version - 8, 8.5, 9, 10, 11, 2008 or whatever. Methods sometimes change between versions, and higher versions have extra options. In this case, it probably makes no difference.

[yinyang] Madawc Williams (East Anglia, UK). Using Crystal 2008 with SQL and Windows XP [yinyang]
 
That worked! Thanks for the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top