Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: How to print specific number of consecutive dates Post Reply Post New Topic
Author Message
Wencone
Newbie
Newbie
Avatar

Joined: 10 May 2010
Location: Australia
Online Status: Offline
Posts: 3
Quote Wencone Replybullet Topic: How to print specific number of consecutive dates
     Posted: 10 May 2010 at 3:47pm
< ="Content-" content="text/; charset=utf-8">< name="ProgId" content="Word.">< name="Generator" content="Microsoft Word 12">< name="Originator" content="Microsoft Word 12"><>

How to print specific number of consecutive dates

Hi everyone.

 

For a couple of days I am trying to solve problem  how to print  only those fields that are related to entered number of consecutive days.

 

User should be able to enter date range (start date, end date) and number of consecutive student absences days (2 or more ). Weekends are not the issue because students are not at school at weekends anyway.

 

Passing parameters is not the problem.

 

This is the report structure and what I have done so far :

 

PHa: Report Title

PHb: Labels

GH1: Group1 (Students Year Level)   ......Field: stuYearLev

GH2: Group2 (Students Name)............... Field: stuName

GH3: Group3 (Students Absences Dates)......Field: stuAbsDate ,   @MainFormula

D:

GF3:

GF2: @ResetDateCount

 

 

MainFormula:

 

shared numbervar conDate;

 

if datediff("d", {vStudentAbsenceEvents.AbsenceEventDate}, next({vStudentAbsenceEvents.AbsenceEventDate})) = 1 then

    (conDate:= conDate +1;

else

  conDate:=0;    //Reset if not consecutive

 

 

ResetDateCount Formula:

 

shared numbervar conDate;

 conseq:=0;

 

So far I am getting this:

 

Student Year 1

                        StudentName1

                                                05/05/2010                                            0.00

                                                06/05/2010                                            1.00

                                                07/05/2010                                            0.00

                                                10/05/2010                                            0.00

                        StudentName2

                                                05/05/2010                                            1.00

                                                06/05/2010                                            0.00

                        StudentName3

                                                10/05/2010                                            0.00

                        StudentName4

                                                07/05/2010                                            0.00

                                                10/05/2010                                            0.00

                        StudentName5

                                                05/05/2010                                            0.00

                                                06/05/2010                                            1.00

                                                07/05/2010                                            0.00

                                                08/05/2010                                            0.00

                                                10/05/2010                                            0.00

Student Year 2

                        StudentName .....

 

And I am trying to get this:

 

Student Year 1

                        StudentName1      3    <- number of consecutive absence days greater or equal two

                                                05/05/2010                     >>

                                                06/05/2010                     >> Or without details of the dates

                                                07/05/2010                      >>

                        StudentName2     2

                                                05/05/2010                                        

                                                06/05/2010                                        

                        StudentName5    4

                                                05/05/2010                                          

                                                06/05/2010                                          

                                                07/05/2010                                        

                                                08/05/2010                                         

Student Year 2

                        StudentName .....


It would be great if someone has an idea or guideline how to solve the problem.

Thanks in advance


Dean Wencone






Edited by Wencone - 10 May 2010 at 4:09pm
D.Wencone
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 11 May 2010 at 3:50am

the reset formula doesn't reset the shared variable.

NEXT() is a tricky function, as it will read regardless of whether value is in the group or not.
 
what I would do to trouble shoot this it to create a formula that is just the datediff formula, and place it in the details (that appear to be suppressed)  or in gh3 and display the date and datediff and that will probably show where the logic is not working at you expected, since everything looks right, but datediff I frequently get backwards.
 
HTH
IP IP Logged
Wencone
Newbie
Newbie
Avatar

Joined: 10 May 2010
Location: Australia
Online Status: Offline
Posts: 3
Quote Wencone Replybullet Posted: 11 May 2010 at 2:01pm

Lockwelle big thanks for replying

Yes you are right. NEXT() function reads all underlying data no meter if the data are grouped.
I am working on  reports development within the existing ERP system. The underlying sql srv. view contains same dates that are repeating.(Wrong entry who knows..)
It looks like:

                CRYSTAL                                   SQL View
StudentName1

        05/05/2010        0.00        |    StudentName1      05/05/2010
        06/05/2010        1.00       |    StudentName1      05/05/2010
        07/05/2010        0.00        |    StudentName1     06/05/2010
        10/05/2010        0.00        |    StudentName1     07/05/2010
                                                       StudentName1    10/05/2010

Now, I am trying to query the view (to make new view for the report) and to somehow exclude the same consecutive dates for the same student.
and to get this (I can't use "distinct" because of the rest fields - some of them has different values)

sql view1

StudentName1     05/05/2010
StudentName1     06/05/2010
StudentName1     07/05/2010
StudentName1    10/05/2010

If anyone have an idea how to  solve this please help

Thanks in advance





Edited by Wencone - 11 May 2010 at 2:12pm
D.Wencone
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 12 May 2010 at 3:24am
well, given the data, this is what I would do:
1) create an additional group by the absence date, this way there is only 1 record displayed per student per date
2) in the group header, I would have a shared variable as to what the absence date is for the header
3) use compare the previous date in the shared variable to the current date in the record for your consecutive calculation.
 
yeah, in coding you would want to reverse 2 & 3 but you get the idea...this way, you would be comparing to the last 'good' date.
 
HTH
 
IP IP Logged
Wencone
Newbie
Newbie
Avatar

Joined: 10 May 2010
Location: Australia
Online Status: Offline
Posts: 3
Quote Wencone Replybullet Posted: 16 May 2010 at 3:25pm
Hi again,
I changed underlying query I  the NEXT() function works well now - no more duplicate records .etc. . But I have this problem that I can't resolve for days.
Now I am getting this:

Student Year 1
    StudentName1
        05/05/2010        1
        06/05/2010        2
        07/05/2010        0
        10/05/2010        0
    StudentName2
        05/05/2010        1
        06/05/2010        0
    StudentName3
        10/05/2010        0
    StudentName4
        07/05/2010        0
        10/05/2010        0
    StudentName5
        05/05/2010        1
        06/05/2010        2
        07/05/2010        3
        08/05/2010        0
        10/05/2010        0
Student Year 2
    StudentName .....

And that is fine. The problem that I can't solve is to get this (to somehow find maximum(@MainFormula) and to group dates again to get this:

Student Year 1
    StudentName1
    Absences: 05/05/2010 - 07/05/2010 , 3 consecutive days

    StudentName2
    Absences: 05/05/2010 - 06/05/2010 , 2 consecutive days

    StudentName5
    Absences: 05/05/2010 - 08/05/2010 , 4 consecutive days

Student Year 2
    StudentName .....

If anyone have an idea please help!


D.Wencone
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 17 May 2010 at 3:15am
ok, here is the general idea/logic that I would use. 1) have 5 variables, something like: abStart, abEnd, abLen, abStart2, abLen2.  The first 3 track the 'first' consecutive absence, the last 2 start to track the next set of consecutive absences.  When the values of the second are bigger than the first, replace them and update the first...that's the general idea of variables.
 
As to the logic...something like...when the student changes, set the startdates to an impossble date...say 1/1/2000. if the # of consecutive days =1, then it is the start of a new string of dates, check the first date flag, if it is 1/1/2000, update it to the current date. when you stop incrementing the consecutive counter, store the end Date.  Next time you start the counter again, check if the dates, and increment the 1/1/2000 date.  Start counting the number of days, if the consecutive count exceeds the prior string of absences, update the first set of variables (start date/length) and reset the 2nd set.  In the group footer, you can now print the dates and length.
 
it's an overview, but hopefully it will give you an idea of how to proceed.
 
HTH
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