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!

Totaling Conditional Formulas

Status
Not open for further replies.

kassea

Technical User
Mar 24, 2008
7
US
I am using Crystal Reports 2008. I have a report grouped by City with each City having a different freight rate. I am using an If Then formula to calculate the freight cost for each City ([Pounds] * Rate). How can I get a grand total of the freight cost? Thank you.
 
Does a simple "Sum" summary (right click on the formula, Insert=>Summary) of the formula not work? If its a simple If-Then-Else is will but if it includes variables, running totals etc you will need to use Variables.

In need, please post a copy of that formula and we can explain how to use it with variables.

Cheers
Pete
 
Here is the formula I am using to calculate the freight:

if{SHIP_TO_INFORMATION_T.SHIP_TO_CITY} IN ["ANNISTON"] THEN {#rt cytd Pounds CITY} * .225
ELSE IF {SHIP_TO_INFORMATION_T.SHIP_TO_CITY} in ["INDIANOLA"] THEN {#rt cytd Pounds CITY} * .215
ELSE IF {SHIP_TO_INFORMATION_T.SHIP_TO_CITY} in ["QUINCY"] THEN {#rt cytd Pounds CITY} * .27
 
hi,

IMNSHO, a nexted if is one of the worse methods to use to do this sort of logic!

This data is best stored in a table for lookup of for joining in your query.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
kassea

It is because you are using Running Totals which you could very easily have avoided by calculating the Freight at the record (detail) level and using simple a Summary to subtotal at the City level and at the Grand Total level.

Anyway, to obtain a Grand Total using your existing approach, replace your formula with the following:

Code:
WhilePrintingRecords;
Local NumberVar CF :=
if{SHIP_TO_INFORMATION_T.SHIP_TO_CITY} IN ["ANNISTON"] THEN {#rt cytd Pounds CITY} * .225
ELSE IF {SHIP_TO_INFORMATION_T.SHIP_TO_CITY} in ["INDIANOLA"] THEN {#rt cytd Pounds CITY} * .215
ELSE IF {SHIP_TO_INFORMATION_T.SHIP_TO_CITY} in ["QUINCY"] THEN {#rt cytd Pounds CITY} * .27; 

Global NumberVar TF := TF + CF;

CF

Then, place the following formula in the Report Footer:

Code:
WhilePrintingRecords;
Global NumberVar TF

Hope this helps.

Cheers
Pete
 
This worked perfectly!! Thank you, Pete.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top