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

Calculations with Subreports

Status
Not open for further replies.

ForMe2

Technical User
Jan 16, 2007
15
0
0
US
I am bringing a calculation into a main report from a subreport with the following formulas:
Formula in the subreport:
WhilePrintingRecords;
Shared CurrencyVar myTotal:=Sum({Orders.Order Amount})

Formula in the main report:
WhilePrintingRecords;
Shared CurrencyVar myTotal;
myTotal

My problem is this: There isn't always a value in the Order Amount field; so there isn't always something to summarize in the subreport groups. Because of this, it carries over the Sum({Orders.Order Amount}) from the group ahead of it into the main report. How do I get it to say 0.00 if the field doesn't contain a value? (Any if/then statements I've tried aren't working.) How would I get it to stop showing the sum from the previous group that contains a value? I have version 10.
 
In a section in the main report just prior to the subreport running place:

WhilePrintingRecords;
Shared CurrencyVar myTotal:=0;

You don't state where the subreport is, so I can't advise you.

-k
 
It is in the only group header in the main report.
 
Hey ForMe2, you can do this a couple of ways. You SHOULD be able to say in the formula in the sub report -

WhilePrintingRecords;
Shared CurrencyVar myTotal;
if Sum({Orders.Order Amount}) = 0 then
myTotal:=0
else
myTotal:=Sum({Orders.Order Amount})


OR you can do it by putting this formula in the Report header of the sub report

@MyTotalStart
whileprintingrecords;
sharedcurrencyvar myTotal;
myTotal := 0

@MyTotal //The formula you already have in the subreport
WhilePrintingRecords;
Shared CurrencyVar myTotal:=Sum({Orders.Order Amount})


Then put this one in the footer
@MyTotalTotal
whileprintingrecords;
sharedcurrencyvar myTotal;
myTotal := myTotal
 
The problem with Robbie's solutions is tht if the subreport has no data, it won't run his code.

It's really simple, right click the group header and select insert section below.

Place the subreport in the lower group header section, and my reset formula in the upper group header section and suppress it.

Now it's always reset PRIOR to running the subreport.

-k
 
That's why I had this part in the code.
"if Sum({Orders.Order Amount}) = 0 then 0"
to account for the sub report not having data. You could also create a default value for the second example I gave but I didn't include it.
 
Thank you! Thank you! Thank you!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top