deLa
deLa

Reputation: 99

Crystal Reports - Incorrect numbers from manual running total

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:

  1. SpecReceived
  2. Unsat/Reject
  3. Number Tests performed

Design template

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)

Running count fields

These are all formula fields and the formulas are:

  1. Reset
    • whileprintingrecords;
    • Shared numberVar SumTotalTestPerf:=0;
  2. Counting iteration (where @totaltestsperformed = field 3)
    • whileprintingrecords;
    • Shared numberVar SumTotalTestPerf;
    • if {@TotalTestsPerformed} <> 0 then SumTotalTestPerf:=SumTotalTestPerf + 1 else 0;
  3. Return Result
    • 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

Answers (2)

deLa
deLa

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

mweber
mweber

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

Related Questions