Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sub Report shows month by month, Main report stores DateVar

Status
Not open for further replies.

sjjcat

Vendor
Jun 10, 2005
8
CA
Hi

Crystal XI, SQL DB

I have 10 sub reports for a set of reports to show monthly patient data (Scary I know)

Jan Feb Mar Apr etc
SR1-Admissions
SR2-Discharges
SR3-PatientDays
SR4-Newborns
etc

I use sub reports because the data qualification in each may be 'slightly' different. I create formulas in each sub report to count the admissions etc for each month

Example:
//@JanAdmissions
if {PatCost_Episode_Category.admitDate} in date(2004,01,01) to date(2004,01,31) then 1

Currently I have these formulas in all the sub reports. But I was thinking when I need to update this for the new year I have to go into every sub report and change the dates. So I was hoping to create a variable in the main report and to have the sub reports use this.


I put this in the main report (and inserted it in the report header)
//@SetDates
beforereadingrecords;
global DateVar JanStart ;
JanStart := Date(2004,01,01);

beforereadingrecords;
global DateVar JanEnd ;
JanEnd := Date(2004,01,31);


I put this in the sub report
//@01Jan
whileprintingrecords;
shared datevar Janstart;
shared datevar Janend;
if {PatCost_Episode_Category.admitDate} in JanStart to JanEnd then 1

But when I run the report I get an error:
A summary has been specified on a non-recurring field. Details: @01Jan

Any guidance/comments much appreciated.

SjjCat
 
You need to define your variables as "shared" not "global" in the main report.

-LB
 
Hi LB, thanks for the reply.

I changed the formula in the main report to:
//@SetDates
whileprintingrecords;
shared DateVar JanStart ;
JanStart := Date(2004,01,01);

But I still receive the same message in the sub report:

A summary has been specified on a non-recurring field. Details: @01Jan

Thanks


 
I can't recreate your problem--your formulas work when I test them. Have you simplified the formula for the thread? Are you using a function like next() or previous() in {@Jan}?

-LB
 
Hi, thanks again.

I am also attempting to summarize my field.

But when I place it on my report in the details section it does not appear as 1.

I started a new report and did the following:
Main Report
//@SetDates
beforereadingrecords;
global DateVar OctStart ;
OctStart := Date(2004,10,01);

beforereadingrecords;
global DateVar OctEnd ;
OctEnd := Date(2004,10,31);

Sub Report
//@01oct
whileprintingrecords;
shared datevar Octstart;
shared datevar Octend;
if {PatCost_Episode_Category.admitDate} in OctStart to OctEnd then 1

And when I place 01Oct into details they all say 0 - I also placed the admit date on the report and there are occurrences of Oct 04 dates.

Should the variable be created in separate formulas in the main report or is it ok to have multiples in the one formula called SetDate?
Is it ok to declare the variablein the same formula in the sub report that I am creating the formula, or should it be in it's own formula?

Thanks
 
First, all your formulas in the main report have to say "shared", not "global". And you could set them all up in one formula, as in:

whileprintingrecords;
shared datevar Janstart := date(2005,01,01);
shared datevar Janend := date(2005, 01, 31);
shared datevar Febstart := date(2005,02,01); //etc.

In the subreports, you don't need to declare the shared variables separately from using them.

This seems like a long way around. You could just set up a parameter for year or use a shared formula for year, as in:

whileprintingrecords;
shared numbervar yearx := 2005;

Then substitute yearx for the year value in each of your subreport formulas, as in:

whileprintingrecords;
shared numbervar yearx;

if {PatCost_Episode_Category.admitDate} in date(yearx, 01,01) to date(yearx, 01,31) then 1

To get back to your first issue, how are you trying to summarize your variables?

I also wonder whether your overall report design could be simplified, but I guess I shouldn't second guess you on that.

-LB
 
Thank-you. I got the values of 1 to appear on the report, and now I can see why my summary won't work. It wont let me sum the detail values.

I tried to create a new formula:
//@OctSum
sum(@10Oct)

but it says the field cannot be summarized. How would I add up the 1's now they are in the detail section?

Thank-you
 
Oh, I see why it can't be summed, because it is not a value available in the sub report - it is only in the main report.
 
Change your subreport formula to:

//{@01oct}:

whileprintingrecords;
shared datevar Octstart;
shared datevar Octend;
numbervar sumoct;

if {PatCost_Episode_Category.admitDate} in OctStart to OctEnd then
sumoct := sumoct + 1;

Then add a second formula:

//{@displsumoct}to be placed in the subreport footer:
whileprintingrecords;
numbervar sumoct;

What groups do you have in the main report? How are your subreports linked to the main report?

-LB
 
Thanks again. I got that working for the footer but now I want to add a group, and of course if I use that same formula then it does not work as it displays a running total up to the group.
Should be
Group 1 10 10
Group 2 15 5
Group 3 20 5
Footer 20 20

The sub reports are only linked via a version_id.

Thanks
 
Ok, I got it!

I created another formula

//@resetoct to be placed in the subreport header:
whileprintingrecords;
numbervar sumoct := 0;

And it all works.

LB - thank-you so much for all your help - it is very much appreciated!

Sue :)
 
Ok, last question.

The first formulas created a value of 1 for each record. But now I have the number of days a patient stayed in hospital. How would this get created in the sub report?

This doesn't work - it generates a value of 1.

//@Mth01
whileprintingrecords;
shared datevar Mth01start;
shared datevar Mth01end;
numbervar sum01;
sum01 := {PatCost_Episode_Results.LengthOfStay};

if {PatCost_Episode_Category.dischargeDate} in Mth01Start to mth01End then sum01 := sum01 + {PatCost_Episode_Results.LengthOfStay};
 
Remove the line:

sum01 := {PatCost_Episode_Results.LengthOfStay};

...since that resets the sum on each record. It should be:

whileprintingrecords;
shared datevar Mth01start;
shared datevar Mth01end;
numbervar sum01;

if {PatCost_Episode_Category.dischargeDate} in Mth01Start to mth01End then sum01 := sum01 + {PatCost_Episode_Results.LengthOfStay};

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top