Solved

Reset variable after each group not working

Posted on 2008-10-06
9
5,129 Views
Last Modified: 2012-05-05
Hi Experts,

Having trouble reseting a variable.  The formula (from mlmcc) works for each detail record however I can not reset the formula between each group.  The formula is:

WhilePrintingrecords;
Global DateVar LastHSDate;
Global NumberVar DaysSince;
If {cp_PS90DayReport;1.SvcID}= 'HS' then
(
    If (LastHSDate = Date(1900,01,01)) then
        DaysSince := 0
    else
        DaysSince := DateDiff('d',LastHSDate,{@convdatetime});

    LastHSDate := {@convdatetime};
)
else
(
    DaysSince := 0;
    LastHSDate := LastHSDate;
);


DaysSince

The formula is in the detail section.  Have tried a reset in the group header but it always shows as zero.

The orginal question is here:

http://www.experts-exchange.com/Database/Reporting_/Crystal_Reports/Q_23657542.html.

What happens is the number of days is being carried forward from one group to the next.  Note that I suppress displaying the formula if the number is less than zero (doubt this matters, just FYI).
Basic beginner with variables.

Thanks in advance.

LBarrett
0
Comment
Question by:LBarrett
  • 4
  • 4
9 Comments
 
LVL 77

Expert Comment

by:peter57r
ID: 22657046
It looks like you need to move the reset formula field from the report header to  the group header.
( to reset the date field - is that what your problem is?)



0
 
LVL 100

Expert Comment

by:mlmcc
ID: 22659513
Do you get the 0 with the data you provided in the other questiion?

mlmcc
0
 

Author Comment

by:LBarrett
ID: 22662903
peter57r

Had the reset formula in the group header - it always displayed zero.  The reset formulas I tried were
if {cp_PS90DayReport;1.AdmSys}<> Previous ({cp_PS90DayReport;1.AdmSys})
then Global NumberVar DaysSince :=0;

and

WhilePrintingrecords;
Global NumberVar DaysSince:=0;

Neither worked, they always returned zero.

mlmcc

What happens is the formula will stay 0 until the condition is met and then it will display the correct number of days.  Then the next group (Patient) that meets the =HS condition is showing the # of days since the previous condition was true.  Each patient can have more than 1 HS type visit in the date range and the first HS visit for each patient should be zero

This is how it is:

Patient A
Visit Type     Date        #Days
HS               1/17/08        0                this is correct
H1               1/21/08
P4               1/23/08

Patient B
P4                1/15/08
No HS visit

Patient C
H1               1/21/08
HS               1/24/08        7                 this should be zero
H2               1/25/08

Patient D
No HS Visit

Patient E
HS                1/21/08       -3                 this should be zero
H4                1/22/08

Patient F
HS                1/15/08       -6                 this should be zero

Patient G
HS                 1/17/08        2                 this should be zero


This is what it should look like:

Patient A
Visit Type     Date        #Days
HS               1/17/08        0
H1               1/21/08
P4               1/23/08

Patient B
P4                1/15/08
No HS visit

Patient C
H1               1/21/08
HS               1/24/08        0
H2               1/25/08
HS               1/28/08        4

Patient D
No HS Visit

Patient E
HS                1/21/08       0
H4                1/22/08

Patient F
HS                1/15/08       0
HS                1/25/08       10

Patient G
HS                 1/17/08        0

Hope this helps to clarify.  I am also unsure why the reset formulas didn't help.  As stated I am fairly "beginner" with variables.

As for the other question I thought the formula was working correctly but since, this I have gone back to look and realize that is doing the same thing.  Didn't see it because the formula was suppressed if <0 and there were always 2nd and 3rd visits that calculated correctly.

LBarrett
     
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:LBarrett
ID: 22662931
The question has become more difficult so I am raising the points.
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 22663449
Try this in the patient group header as the reset

WhilePrintingrecords;
Global DateVar LastHSDate;
Global NumberVar DaysSince;
LastHSDate := Date(1900,01,01);
DaysSince := 0;
''

mlmcc
0
 

Author Comment

by:LBarrett
ID: 22663912
This works unless the group is more than one page.  I have the "Repeat Group Header on each page" checked.  If  I remove the check then the reset works correctly.  Otherwise it starts over again on each page at zero.  Put it in the group footer and that seems to work.  Any issues you can see with having it in the last group footer?
0
 
LVL 100

Accepted Solution

by:
mlmcc earned 500 total points
ID: 22664258
You can change the formula to

WhilePrintingrecords;
Global DateVar LastHSDate;
Global NumberVar DaysSince;
If Not InRepeatedGroupHeader then
(
    LastHSDate := Date(1900,01,01);
    DaysSince := 0;
)
''

mlmcc
0
 

Author Comment

by:LBarrett
ID: 22664901
Tried this:
WhilePrintingrecords;
Global DateVar LastHSDate;
Global NumberVar DaysSince;
If Not InRepeatedGroupHeader then
(
    LastHSDate := Date(1900,01,01);
    DaysSince := 0;
)
''
Had to add semicolon after last close paren and then it worked great.

Thanks again mlmcc it's just what I needed.

LBarrett
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 22665716
Sorry.  I missed that.

mlmcc
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question