Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: select statement within formula editor Post Reply Post New Topic
Author Message
supportagent11
Newbie
Newbie


Joined: 31 Aug 2011
Location: United States
Online Status: Offline
Posts: 1
Quote supportagent11 Replybullet Topic: select statement within formula editor
     Posted: 31 Aug 2011 at 9:11am
Assuming I have the following database values of shapes, colors, and weights:
square, blue, 3
triangle, red, 2
triangle, green, 5
square, red, 3
circle, green, 6
triangle, purple, 1
circle, blue, 3
square, green, 7
square, purple, 1
triangle, red, 4
triangle, red, 2
triangle, blue, 4
triangle, green, 1


For this example, I am trying to write formula fields that report back specific sums of weights.

since I am only concerned with triangles, I have entered in my select expert:
{data.shape} = "triangle"

If I were to use the formula:
sum({data.weight})
I would expect a result of "22" (the total weight of all triangles)

Now I would like to write formulas that will report back the total weight of triangles that have specific colors (including colors that are not in the database yet):
blue - 7
red - 8
green - 6
purple - 1
black - 0
total - 22


Without using groups, is it possible to write a select statement within the formula editor, similar to:
sum({data.weight}, {data.color} = "blue")
so that can calculate a sum of weights within a specific color?

I had originally tried using a group subtotal with limited success, but now need to have more control over how the results display (my live data is a little more complicated than this example). The @formula for each sum will be added into text fields on the report, which is already designed.

Edited by supportagent11 - 31 Aug 2011 at 9:44am
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 31 Aug 2011 at 10:23am
you can get to the same end result but not in the way you were attempting. You have to do this per row not at the aggregate.
the 3 main ways to do this
1. make a fomula to convert your weight per row based on your criteria
if shape=triangle and color=blue then weight else 0
sum this and you get the total of only blue triangles
2. make shared variable formulas to include or exlcude each row based on your criteria. lots of eaxmples on this forum and a favorite process for many.
3. Running Total
field to summarize=weight
type of summary=sum
evaluate = use a formula e.g. color=blue
reset= never
place in report footer
 
Note options 2 and 3 do not work in headers


Edited by DBlank - 31 Aug 2011 at 10:24am
IP IP Logged
sharona
Senior Member
Senior Member
Avatar

Joined: 16 Oct 2008
Location: United States
Online Status: Offline
Posts: 255
Quote sharona Replybullet Posted: 31 Aug 2011 at 10:33am
create a group by shape
group by color
use manual running totals to calculate the value of the weight on each shape then color.
 
RESET VALUE
insert into group header
whileprintingrecords;
numbervar shape := 0;
 
CALC VALUE
place in details next to the field
whileprintingrecords;
numbervar shape := shape +{weight};
 
DISPLAY VALUE
place in group footer
whileprintingrecords;
numbervar shape;
shape
 
create another set for color
 
create a parameter for the shape
in the parameter  set up add
ALL
square
triangle
circle
 
in the record selection replace what you have with
 
this will allow the end user to select all the shapes or one shape
 
sharona
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