Print Page | Close Window

How to sum a shared variable

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Report Design
Forum Discription: The best way to design a report and problems you have encountered
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=6978
Printed Date: 03 May 2024 at 2:30pm


Topic: How to sum a shared variable
Posted By: duffey01
Subject: How to sum a shared variable
Date Posted: 06 Jul 2009 at 10:57pm
Hi All
 
I have spent most of the day on this and I feel I should be able to do this, this is my last resort.
 
Using Crystal XI I have a main report with some totals from a subreport using a shared variable. I have the shared variable displaying on my main report and all looks good. What I can't do is create the right formula or place the right formula on the report to get a total of these figures in the report footer.
 
Report looks like this
details a;
 
@sumtotal
whileprintingrecords;
numbervar sumtotal:=0;
 
details b;
subreport
 
details c;
@sum of shared
whileprintingrecords;
numbervar sumtotal;
shared numbervar lineamt;
sumtotal:=sumtotal+lineamt; (this calculates and displays fine)
 
RF;
whileprintingrecords;
numbervar sumtotal;  (this displays as 0)
 
What I need is a total of 'lineamt' in RF.
 
What have I done wrong??
 
Thanks very much



Replies:
Posted By: gurupran
Date Posted: 07 Jul 2009 at 4:40am
hi
 
u did small mistake.
 
u use sharedvariable but shows normal filed
 
want to print shared numbervar lineamt;
 
try this
 
shared numbervar sumtotal;
shared numbervar lineamt;
sumtotal:=sumtotal+lineamt;
 
In RF:
Shared numbervar lineamt;
 
its working sure
 
 
 
 
 


-------------
guru


Posted By: lockwelle
Date Posted: 07 Jul 2009 at 6:24am
It would seem that there is a record that is resetting your counter to 0 before the RF.
 
since you want a total of all lineamt, remove the formula that resets the total to 0.  Does this give you what you want?
 
If you want a total for a group and big total for the report, create another variable and increment that one as well, but never reset it, this way it will be the total for the report.
 
HTH


Posted By: duffey01
Date Posted: 07 Jul 2009 at 6:16pm
Hi lockwelle
 
It certainly did help. I got rid of @sumtotal and I have my total. Thankyou so much, I have learnt yet something else about Crystal.



Print Page | Close Window