Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Reset variable after each group not working

Posted on 2008-10-06
9
Medium Priority
?
5,566 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 101

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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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 101

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 101

Accepted Solution

by:
mlmcc earned 2000 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 101

Expert Comment

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

mlmcc
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

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…
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 …
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

824 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