Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: sum of a calc from a variable Post Reply Post New Topic
Author Message
jlwilde
Newbie
Newbie
Avatar

Joined: 31 Dec 2009
Location: United States
Online Status: Offline
Posts: 6
Quote jlwilde Replybullet Topic: sum of a calc from a variable
     Posted: 02 Nov 2011 at 4:51am
Hello, I need some assistance please.  I have a subreport in the group header 2 and declared as a varible which I have placed in the details section.  Then have made many formula's and additional colunms on report.  Now I am unable to sum final two columns because of use of variables.  I have read the complete reference crystal rpt 10 on use of variable, reporting passes and "evaluate after".  I cannot understand it, and all I need is a sum of a column containing a calc against a variable.  I am willing to let someone remote into my PC for any assistance as this report was due last week and I'm stuck.
 
Any assistance will be greatly appreciated!
 
JlWilde, Diehl Food Ing.
IP IP Logged
FrnhtGLI
Senior Member
Senior Member
Avatar

Joined: 22 May 2009
Online Status: Offline
Posts: 347
Quote FrnhtGLI Replybullet Posted: 02 Nov 2011 at 6:30am
Do you know anything about creating three-formula manual running totals? I would have to know your data a bit better to understand if that would work, but it might be a solution.
|< /\ '][' ( )
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 02 Nov 2011 at 6:33am
since I am not a Running Total person, I don't know if that is a viable solution path, but using variables, that I know.
 
since you are using a subreport to generate the number, I will assume that you are using a shared variable. Now the question is, what else do you need to do.
 
If you just summing a column and then adding the shared variable to it, I would try:
shared numbervar sharedVar;
sum({table.field}, {group}) + sharedVar
 
if you need to update the totals based on some condition
shared numbervar sharedVar;
if {table.fieldx} = x then
  sharedVar := sharedVar + {table.fieldy};
 
this would increment/display the new value.
 
 
In general, the summing of a variable can be simplified to this: If CR can see the value in the raw data, on the first pass, it can sum it.  Since it can't see the value that would be returned from a subreport, you can sum using the variable/formula.  If you had a field for sex, you could create a formula like: if {table.sex} = "M" then 1 else 0
 
and you could sum that...I haven't but DBlank uses it all the time in his posts, I have done something similar as I use that sort of logic to perform dynamic grouping.
 
It all comes down to what CR can 'see' in the raw data as to whether or not you can sum on it.
 
HTH
IP IP Logged
jlwilde
Newbie
Newbie
Avatar

Joined: 31 Dec 2009
Location: United States
Online Status: Offline
Posts: 6
Quote jlwilde Replybullet Posted: 02 Nov 2011 at 7:47am
HTH, thanks for responding.  Look below
 
Prt#       Qty       Jan     Wetused   Totalsolidsused
B10       200           75         125                120
S03        110          23           86                  77
 
Above is report example:  Prt# is a dbfield, "Qty" is a dbfield.  "Jan" is the subreport numbers that I have declared as a Shared numbervar.  "Wetused" is {DBfiled}-@jan.  "Totalsoldsused" is {@Westused}*(1-(dbfield)*.01)).  All of these reside in the details section.  How do I sum "Totalsoldsused", it will not let me even do a running total.  The book says something about "evaluale after" that i have tried to use but i can not get it to work either.
 
 
JlWilde, Diehl Food Ing.
IP IP Logged
jlwilde
Newbie
Newbie
Avatar

Joined: 31 Dec 2009
Location: United States
Online Status: Offline
Posts: 6
Quote jlwilde Replybullet Posted: 02 Nov 2011 at 7:49am

No I do not know anything about three-formula manual running totals but i am desperate for assistance.  See my other response below to help you understand my data.

Prt#       Qty       Jan     Wetused   Totalsolidsused

B10       200           75         125                120
S03        110          23           86                  77
 
Above is report example:  Prt# is a dbfield, "Qty" is a dbfield.  "Jan" is the subreport numbers that I have declared as a Shared numbervar.  "Wetused" is {DBfiled}-@jan.  "Totalsoldsused" is {@Westused}*(1-(dbfield)*.01)).  All of these reside in the details section.  How do I sum "Totalsoldsused", it will not let me even do a running total.  The book says something about "evaluale after" that i have tried to use but i can not get it to work either.
JlWilde, Diehl Food Ing.
IP IP Logged
FrnhtGLI
Senior Member
Senior Member
Avatar

Joined: 22 May 2009
Online Status: Offline
Posts: 347
Quote FrnhtGLI Replybullet Posted: 02 Nov 2011 at 8:24am
Create a formula and name it whatever (I usually do something like CalculateTotalSolidsUsed):

whileprintingrecords;

global numbervar nTotal:=nTotal + {@TotalSolidsUsed};

nTotal;


To display it, create another formula DisplayTotalSolidsUsed:

whileprintingrecords;

global numbervar nTotal;

Drop the Calculate field on the detail line that the TotalSolidsUsed field is displayed and suppress it.

Place the display field where you want the total to display.
|< /\ '][' ( )
IP IP Logged
jlwilde
Newbie
Newbie
Avatar

Joined: 31 Dec 2009
Location: United States
Online Status: Offline
Posts: 6
Quote jlwilde Replybullet Posted: 02 Nov 2011 at 9:26am
IT WORKED, I CAN'T THANK YOU ENOUGH!!!!!!
JlWilde, Diehl Food Ing.
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 02 Nov 2011 at 10:19am
Glad we could help.
 
just remember that global actually has a smaller scope than shared.
 
you could also increment your total in the same formula that you calculate the totalSolidUsed, like:
 
shared numbervar aTotal;
local numbervar used;
 
aTotal := aTotal + used;
used;
 
 
CR displays whatever is the last line of the formula, which you can use to your advantage.  When I want to hide the output of the formula, I simply place "" as the last line...and CR shows an empty string.
 
HTH
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum