Avatar of cozmo_troll
cozmo_troll
 asked on

Sum in Report Footer; sum formula field

I have a report that includes data and shared variables from several subreports. I have all of the individual formulas working correctly, but I need to do some total fields in the report footer now. When I try to do this it either tells me that I must enter a field here or that this field can not be summed. Ideas please?
Crystal Reports

Avatar of undefined
Last Comment
Mike McCracken

8/22/2022 - Mon
analliah

I'm assuming that you are trying to sum the fields from the subreports and the main report into your report footer.
cozmo_troll

ASKER
Sort of; there are calculated fields using the fields from the subreports that I am trying to sum in the footer.
Mike McCracken

Since the formulas use SHARED variables they are calculated in the PRINTING RECORDS pass.  Yhe summary functions are done in an earlier pass so they can't be used.

You will need to do the summary through formulas and variables

Add a formula to the report header to declare a global variable for the total.

WhilePRintingRecords;
Global NumberVar MyTotal := 0;

Where you have the value to be totaled
WhilePRintingRecords;
Global NumberVar MyTotal;
Shared NumberVar MyShared;

MyTotal := MyTotal + MyShared;

In the report footer
WhilePRintingRecords;
Global NumberVar MyTotal;
 MyTotal

mlmcc
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
cozmo_troll

ASKER
mlmcc,

Ok, I have the first and last part and they both show zero. However, I do not understand how to do the middle part. I'm not just needing to sum an individual Shared Var; the shared Vars are used along with other data to create totals in the data of the report; I need to sum those totals, not the individual var?
analliah

mlmcc,
 does this take care of all the different formula that you are adding from the different subreport.
Mike McCracken

Can you post the report to this site or one of the formulas you need totaled?

mlmcc
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
cozmo_troll

ASKER
This is the formula I needed totaled: {@ASP}*{@TotalQtyOnCustomerOrders}

>>@ASP's formula is: if ({@TotalQtyOnCustomerOrders}>0) then formula =(({@TotalPriceOrders}+{@TotalPriceInvoices})/{@TotalQtyOnCustomerOrders})

>>@TotalQtyOnCustomerOrders formula is:formula={@QtyOnOrder2}+{@QtyOnOrderTotal}

>>@QtyOnOrder2's formula is:WhilePrintingRecords;shared numberVar TotalQtyOnOrders

>>@QtyOnOrderTotal's formula is:WhilePrintingRecords; shared numberVar TotalQtyOnInvoices

Thank you!
Mike McCracken

In the formula {@ASP}*{@TotalQtyOnCustomerOrders}
Crystal synax
Global NumberVar MYTotal;
Local NumberVar CurrentValue;
CurrentValue := {@ASP}*{@TotalQtyOnCustomerOrders};

MyTotal := MyTotal + CurrenValue;
CurrentValue

mlmcc
cozmo_troll

ASKER
mlmcc,

I'm sorry if I am stupid and don't understand something. But, when I copy what you have above into the formula called: Gross (the original formula name that contains  {@ASP}*{@TotalQtyOnCustomerOrders}) it comes up with "The remaining text does not appear to be part of the formula.

This is what the entire formula looks like, and it is in Crystal syntax:
{@ASP}*{@TotalQtyOnCustomerOrders}
Global NumberVar MYTotal;
Local NumberVar CurrentValue;
CurrentValue := {@ASP}*{@TotalQtyOnCustomerOrders};

MyTotal := MyTotal + CurrenValue;
CurrentValue
Your help has saved me hundreds of hours of internet surfing.
fblack61
cozmo_troll

ASKER
Never mind. I figured it out by elimnating the top line and also correcting the typo in the 2nd to last line. Thank you.
cozmo_troll

ASKER
mlmcc,
could you advise one other thing quickly? I have a similar field that needs an average?
ASKER CERTIFIED SOLUTION
Mike McCracken

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.