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:
Shot of CR showing location data  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!
LVL 1
Tina KSystems SpecialistAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Tina KSystems SpecialistAuthor Commented:
Here's a shot that has better data:

Location-Snap-2.pdf
0
mlmccCommented:
From the PDF I can't tell which section the pieces are in.
The problem is if the subreport has no data then the formula never executes to set it to the  0 value.

You need to set the shared variable to 0 in the mainreport either in the group header or in the group footer.  It can't be in the section wherever the subreport is or where you display it in the main report.


I suspect what you need is to add a formula to either the main report group header/footer that 0's the shared variables

shared numbervar subtot1; 
 subtot1 := 0;
''

Open in new window


mlmcc
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mlmccCommented:
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
0
Tina KSystems SpecialistAuthor Commented:
Thank you mlmcc - perfect solution!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Crystal Reports

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.