Crystal Reports Training by Ken Hamady, MS, Reporting and Training Nationwide On Location TrainingPublic ClassesIndividual TrainingIntroductory Course OutlineAdvanced Course OutlineFormula ExamplesNewsletter Back IssuesMy BlogResource LibraryConsulting ServicesSupport ServicesContact InformationLinks to third party productsBack to main pageMy Credentials
Free Crystal Reports formula examples from KenHamady.com


To learn the techniques used in these formulas get:


The Expert's Guide to Crystal Reports Formulas
and
 Expert Techniques for Crystal Reports I, II & III

Conditional Total using an If-Then-Else formula:

One of the most common ways to do a conditional total is to use an If-Then-Else formula.  This has an advantage over the other techniques because it can be used to display a total at the beginning of the report or group.  The other techniques can only display their totals at the end of the repor or group.  The If-Then-Else formula technique requires 2 steps:

1) Create an If-Then-Else formula for each condition that you wish to total.  The result of the formula will be a 1 in cases where you wish to count the condition or a numeric field in cases where you wish to Sum the field.   For instance to count records in the state of Virginia:

 if {Customer.Region}  = 'VA'
 then 1
 else 0


To sum records in the state of Virginia:

 if {Customer.Region}  = 'VA'
 then {Orders.Amount}
 else 0


2) Insert a normal Summary, Subtotal or Grand Total of the formula using the Sum operation.  Even when trying to count conditional records with the first formula above, you must use the Sum operation.  Counting the formula will also count the zeros.