Reputation: 99
I have inherited a crystal report used to pull counts of statistics from a database (Crystal Reports 2016). I've been trying for a week and I cannot complete my last modification and I don't understand why. With that being said I am only 3 weeks into crystal so please be blatant with responses.
Fields:
Fields 1 & 2 are running total fields that are pulling distinct counts from the database via SQL.
Field 3 is a formula field that subtracts Field1 from Field2 if Field1 is not 0.
I am simply trying to get a total sum of Field 3.
I figured out I can't just insert a running total field to do the SUM because it seems like I can only do that if I'm pulling the numbers straight from the database, so I found I had to create a manual running count, which I did (fields highlighted below)
These are all formula fields and the formulas are:
whileprintingrecords;
Shared numberVar SumTotalTestPerf:=0;
whileprintingrecords;
Shared numberVar SumTotalTestPerf;
if {@TotalTestsPerformed} <> 0 then SumTotalTestPerf:=SumTotalTestPerf + 1 else 0;
whileprintingrecords;
Shared numberVar SumTotalTestPerf;
SumTotalTestPerf
From my understanding, every time the count of {@TotalTestsPerformed}
increases, so should my variable. But my results are off.
The last thing I can come up with is that the {@TotalTestsPerformed}
is being populated at once, not per record..if that makes sense.
If someone could please enlighten me on what I'm doing wrong it would be much appreciated.
Upvotes: 0
Views: 118
Reputation: 99
Finally. Dragged {@TestPerfCnt} with the formula:if {@TotalTestsPerformed} <> 0 then SumTotalTestPerf:=SumTotalTestPerf + {@TotalTestsPerformed};
to Group Footer 4. It gives me a summed running count, not 1 summed value, but it'll work for now.
Upvotes: 0
Reputation: 688
From my understanding, every time the count of {@TotalTestsPerformed} increases, so should my variable.
That's not completely correct. In fact, your variable increases every time the formula performing the increase operation is "printed". In your case it's located in Details section, so it will be run for every detail or row in your resultset.
Upvotes: 0