Solved

Reset variable after each group not working

Posted on 2008-10-06
9
5,281 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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 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 101

Expert Comment

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

mlmcc
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
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 …
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

691 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