Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Limit Sum Calculation Post Reply Post New Topic
Author Message
Razzy
Newbie
Newbie
Avatar

Joined: 14 Oct 2009
Online Status: Offline
Posts: 6
Quote Razzy Replybullet Topic: Limit Sum Calculation
     Posted: 14 Oct 2009 at 7:36am

I am having difficulty calculating the sum of a number field for only those data records that match a specific criterion.

 

In the SQL Database I am working with two fields:

InspectionDefects.DispCode and InspectionDefects.NumberDefectiveParts.

 

What I am trying to do is calculate the sum of the NumberDefectiveParts field for only the records where the DispCode = 'RTS'.

 

I have tried the IIF statement of:

 

iif({InspectionDefects.DispCode}= 'RTS',Sum ({InspectionDefects.NumberDefectiveParts}, {Inspection.InspectionDate}, "monthly"),0)

 

This doesn’t work for me.  If there are any records where the DispCode <> ‘RTS’ then the Formula Field Value always returns 0.

 

Example:  If I have 5 records with the following values (DispCode), (NumberDefectiveParts).

 

RTS, 3

ACC, 3

RTS, 1

RTS, 5

ACC, 2

 

The value of the formula fields should be nine (9) the sum of the NumberDefectiveParts where DispCode = ‘RTS’ or 3+1+5 = 9.

 

Any help would be most appreciated.

Razzy

"Artificial Intelligence is no match for Natural Stupidity"
Harold Green
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 14 Oct 2009 at 8:06am
Make a formula to convert your associated values then sum that formula field (at any group level you need it):
if {InspectionDefects.DispCode}= 'RTS' then {InspectionDefects.NumberDefectiveParts} else 0


Edited by DBlank - 14 Oct 2009 at 8:07am
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 14 Oct 2009 at 8:08am
You can also use variables or Running Totals that conditionally include rows in your Sum.

Edited by DBlank - 14 Oct 2009 at 8:08am
IP IP Logged
Razzy
Newbie
Newbie
Avatar

Joined: 14 Oct 2009
Online Status: Offline
Posts: 6
Quote Razzy Replybullet Posted: 14 Oct 2009 at 8:53am

DBlank,

I used the recommendation from you first post and I was able to get the data filtered as requested. 

 

Thank you for your insight.

Razzy

"Artificial Intelligence is no match for Natural Stupidity"
Harold Green
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