Link to home
Start Free TrialLog in
Avatar of Tina K
Tina KFlag for United States of America

asked on

Crystal Reports Sub-report formula

Hello all -

I've created a report that we use for counting inventory in a warehouse environment.  The main report takes the location parameter, adds titles, displays how many locations are being counted, and also a running total of how many individual parts were counted, based on a variable formula from the subreport.  I had this all working great until we realized that locations without inventory were not being shown, so I remedied that by removing the part.qty>0 from just the main report, but leaving on the subreport, which shows the actual part numbers and piece counts of the location.

Works great, but the formula is adding the value from the last location for each subreport, even if there are no records in the subreport:
User generated image  You can see that the "Running total of parts counted" is adding 5 for each instance of the subreport, when it should not be.  How do I make this go away?

Here's how the formulas work:
In subreport:  
 formula @subtot2  (in report footer, hidden)
shared numbervar subtot1;
subtot1:= sum({command.part_qty});

In main report:
formula @grandtot (in group footer)
shared numbervar subtot1;
subtot1;
numbervar x;
x:= x+subtot1

Like I said, everything works exactly how I need with the exception of the 'bonus' addition.

Thanks in advance!
Avatar of Tina K
Tina K
Flag of United States of America image

ASKER

Here's a shot that has better data:

Location-Snap-2.pdf
ASKER CERTIFIED SOLUTION
Avatar of Mike McCracken
Mike McCracken

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mike McCracken
Mike McCracken

Just had a thought.  You could also do it in the grandtotal formula

shared numbervar subtot1; 
 subtot1;
 numbervar x;
 x:= x+subtot1;
subtot1 := 0;
x

Open in new window


mlmcc
Avatar of Tina K

ASKER

Thank you mlmcc - perfect solution!