Totals for a Special group deduction in Crystal Reports

csenor used Ask the Experts™
I am having problems with a total in Crystal Reports. I have a report that has 2 Groups. I need to make a specific deduction for each group that is not related to the detail records. I have created that special deduction with the following formula:

if {Database.ItemClass} = "Group A" then 2000 else
if {Database.ItemClass} = "Group B" then 3000 else 0  

That works fine until I go to get a Grand Total of Groups A & B for the special deduction field. There is not a problem with other fields because they exist in the detail, but with this special field the amounts exist at the Group Level only.

I would appreciate any help. I certainly think that Crystal Reports would be able to keep a total for these "special' amounts, but I can not find the solution in my manuals.  

Here is the format of my report:

                  Item Name      Qty            Expense            Special Deduction
      detail            Item A1            10            3,000      
      detail            Item A2            10            3,000
      detail            Item A3            10            3,000      
Group       Group A Totals            30            9,000            2,000
      detail            Item B1            20            6,000      
      detail            Item B2            20            6,000      
Group      Group B Totals                    40            12,000            3,000
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Senior Consultant
Most Valuable Expert 2011
Top Expert 2013
You have to do the totals manually with variables.

Are you looking for a total for this formula for the report?

Try this

Add a formula in the report  header
Name DeclareVariables
Global NumberVar SPecialTotal;

Open in new window

Modify your formula

Global NumberVar SPecialTotal;
Local NumberVar DispValue;

if {Database.ItemClass} = "Group A" then 
    DispValue := 2000 
else if {Database.ItemClass} = "Group B" then 
    DispValue := 3000 
    DispValue := 0 ;
SPecialTotal := SPecialTotal + DispValue;

Open in new window

Add a formula to the report footer
Name - DisplaySpecialTotal
Global NumberVar SPecialTotal;

Open in new window

If you want to get a total of the special deduction formula, but only include it once per group, you could use a running total.

 Put your special deduction formula in the detail section, right-click and select Insert > Running Total.  Under Evaluate select "On change of group" and select your group.  Then the value from that formula will only be added once for each group.  After you create the running total, you can remove that formula from the detail section.



This advice me in the right direction. I had a problem with the variables keeping a running total, but I learned how to reset the variable after the group printed. Thanks for the advice----

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial