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

Group Sum

Status
Not open for further replies.

lauriebizz

Technical User
Sep 19, 2005
53
US
Hi - I've got a question. I've got Crystal 9/SQL

Current record select formula:
{matltran.trans_type} in ["F"] and
{matltran.trans_date} = Today()-1 and
{item.product_code} = "FG" or
({matltran.trans_type} in ["M"] and {matltran.loc} in ["HDC"]) and
{matltran.trans_date} = Today()-1 and
{item.product_code} = "FG"

I need to sum the {matltran.qty} for type F minus the {matltran.qty} for type M at the group {maltran.item} level.

Any suggestions?
Thanks-
Laurie
 
Do running totals for each type for the group. Display (to be sure you have the right totals) and then use a formula field to subtract.

There are several ways to find totals: running totals, summary totals and variables. Right-click on a field and choose Insert to get a choice of Running Total or Summary. Or else use the Field Explorer, the icon that is a grid-like box, to add running totals.

Running totals allow you to do clever things with grouping and formulas. They also accumulate for each line, hence the name. The disadvantage is that they are working out at the same time as the Crystal report formats the line. You cannot test for their values until after the details have been printed. You can show them in the group footer but not the group header, where they will be zero if you are resetting them for each group.

Summary totals are cruder, but are based directly on the data. This means that they can be shown in the header. They can also be used to sort groups, or to suppress them. Suppress a group if it has less than three members, say. They default to 'Grand Total', but also can be for a group.

Variables are user-defined fields. One useful variant are shared variables to pass data from a subreport back to the main report. You can also use variables to show page totals. For normal counting I find running totals or summary totals much easier.

Directly Calculated Totals within a Formula Field can be coded directly, with commands like Sum ({ADV01.Advance}, {ADV01.AccType}). The same result can be achieved by picking up an existing Variable, and will keep the code even if the Variable itself is later deleted. Formula fields can also include Running Totals and other Formula Fields, with some limits depending on when the values are calculated.

It is also possible to get totals using a Formula Field, which can contain a Variable or a Directly Calculated Total.

To get yourself familiar with the idea, try doing a test report with a summary total and a running total for the same field, placed on the detail line. You'll find that the running total increases as each line is printed, whereas the summary total has the final value all along.

[yinyang] Madawc Williams (East Anglia, UK). Using Windows XP & Crystal 10 [yinyang]
 
Thanks - I actually solved it last night the way you suggested!

Laurie
 
Hi,

I have a similar problem, I want to sum the "Amount" field for types I and R, and then find the difference between these sums. I read this post, and was confused as to how to create the difference formula. I have the sums created, and they work fine, but I just can't seem to wrap my head around the subtraction part. Any assistance would be appreciated.

~Gene
 
Have you tried this very simple formula:

sum({field1})-sum({field2})

Software Sales, Training, Implementation and Support for Macola, eSynergy, and Crystal Reports
 
Create two conditional formulas like the following for the detail section:

//{@I}:
if {table.type} = "I" then {table.amt}

//{@R}:
if {table.type} = "R" then {table.amt}

Then create a third formula:

sum({@I},{table.groupfield}) - sum({@R},{table.groupfield})

if you are calculating at the report level, you would remove the group conditions in the last formula.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top