Solved

Reset variable after each group not working

Posted on 2008-10-06
9
4,942 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
Comment Utility
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
Comment Utility
Do you get the 0 with the data you provided in the other questiion?

mlmcc
0
 

Author Comment

by:LBarrett
Comment Utility
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
 

Author Comment

by:LBarrett
Comment Utility
The question has become more difficult so I am raising the points.
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Sorry.  I missed that.

mlmcc
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now