Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Complex counting - Solved - Post Reply Post New Topic
Author Message
levifiction
Newbie
Newbie


Joined: 13 Feb 2013
Online Status: Offline
Posts: 6
Quote levifiction Replybullet Topic: Complex counting - Solved -
     Posted: 30 Apr 2013 at 1:41pm
This is most likely a logic error on my part more than anything.

I have a report based on student absences. And I successfully got it to count all absences, per class, per student.

I was recently informed that they also wanted a count of the most recent continuous absences. As well as the greatest count of continuous absences.

For example let's say one of our students has 13 absences this semester. He missed 1 class, then he missed 8 classes in a row, then a few weeks later he misses 4 in a row. And he's present for the rest of the semester.

Greatest would be 8, most recent would be 4.

I thought I had a good working formula but they always return 0.

The report is organized like so: Group 1: Student, Group 2: Course, Group 2 Details: Recorded Attendance Dates and attributes.

In Group 2 Header - I have 1 formula
-------------------
WhilePrintingRecords;
global NumberVar TotalAbsent:= 0;
global NumberVar TotalConsecutive:= 0;
global NumberVar RecentConsecutive:= 0;
global NumberVar GreatestConsecutive:= 0;
-------------------

In group 2 details I have two formulas
-------------------
//Record Total Absences
whileprintingrecords;
global NumberVar TotalAbsent;
global BooleanVar DisplayAbsent;
//If Atnd_ID = Absent then increase total count
//If count is greater than our parameter
//Tell Group 1 to display
if {SR_STUD_ATTEND.ATND_ID} = "A" then
    TotalAbsent := TotalAbsent + 1;
    if TotalAbsent > {?Num of Absences} then
        DisplayAbsent = True
-------------------
-------------------
//Record Greatest Consecutive
WhilePrintingRecords;
global NumberVar TotalConsecutive;
global NumberVar RecentConsecutive;
global NumberVar GreatestConsecutive;

//If absent, increase Consecutive count
if {SR_STUD_ATTEND.ATND_ID} = "A" then
    TotalConsecutive:= TotalConsecutive + 1
//If not absent reset
else if TotalConsecutive > 0 then
        // If current consecutive count is greater than the last one
        if TotalConsecutive > GreatestConsecutive then
            GreatestConsecutive:= TotalConsecutive;
        //Assign last count to Recent
        RecentConsecutive:= TotalConsecutive;
    //Reset Total Consecutive
    TotalConsecutive:= 0;
-------------------

The final forumlas are placed in the Group 2 Footer. The footer is supressed if TotalAbsent is less than to the parameter for allowed absences.

The formulas simply return "TotalAbsent", "GreaterConsecutive" and "RecentConsecutive.

Again, TotalAbsent is returned properly. The GreatestConsecutive and RecentConsecutives are not.

Can anyone see anything potentially wrong with my method here?

Edited by levifiction - 02 May 2013 at 8:33am
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 01 May 2013 at 5:51am
Yes, I would change the second formula to this:
 
//Record Greatest Consecutive
WhilePrintingRecords;
global NumberVar TotalConsecutive;
global NumberVar RecentConsecutive;
global NumberVar GreatestConsecutive;

//If absent, increase Consecutive count
if {SR_STUD_ATTEND.ATND_ID} = "A" then
TotalConsecutive:= TotalConsecutive + 1
//If not absent reset
else if TotalConsecutive > 0  or OnLastRecord or
  {SR_STUD_ATTEND.<studentIDfield>} <> next({SR_STUD_ATTEND.<studentIDfield>}) then (
// If current consecutive count is greater than the last one
if TotalConsecutive > GreatestConsecutive then
GreatestConsecutive:= TotalConsecutive;
//Assign last count to Recent
if TotalConsecutive > 0 then
RecentConsecutive:= TotalConsecutive;
//Reset Total Consecutive
TotalConsecutive:= 0; )
 
If you don't have the parentheses, Crystal will always evaluate the statements instead of only evaluating them if it's not an absence.  I would also force the evaluation on the last record for the student or the last record in the report.  Otherwise you migh miss a set of consecutive absences if they are the last records for the student.
 
-Dell
IP IP Logged
levifiction
Newbie
Newbie


Joined: 13 Feb 2013
Online Status: Offline
Posts: 6
Quote levifiction Replybullet Posted: 02 May 2013 at 5:18am
Thank you very much. That seems to have worked perfectly.

I'm getting some odd results. It looks like at all times students miss exactly the same greatest and recent consecutive absences as total absences. This is expected in some cases, but it seems to be that way in all cases.

I'm using the details section of Group 2 as a sort of debug print view to slowly verify al 33,000 records. If it pans out, then this is a success.

:D

EDIT: I feel silly. It was sorting by the Attendance ID so all absences were right next to each other. Forced a sort by date and it's working perfectly.

Thank you again.

Edited by levifiction - 03 May 2013 at 5:27am
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