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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

formula to look at last year's data

Status
Not open for further replies.

adnil

Technical User
Oct 29, 2003
50
GB
We have a string field that contains years, eg 2004/2005, 2005/2006. In the main report, users will be prompted to select their required year. The sub-report is then supposed to pull out the data from the previous year. So if users select 2005/2006, the sub-report should show 2004/2005 data. How should I write the formulas in the sub-report to achieve this?

Thank you.
 
You likely don't need a subreport to do this.

Just set your record selection formula to include all records from both years. Then create a formula @ThisYr

Code:
if {YourYearField} = {?YourParameter} then {YourDataField} else 0

and for the prior year:

Code:
if {YourYearField} = {?YourParameter}-1 then {YourDataField} else 0

Then place these 2 fields on the report and summarize as needed.

Software Sales, Training, Implementation and Support for Macola, Synergy, and Crystal Reports. Check out our Macola tools:
 
Create a string parameter {?Year} in the subreport that is exactly like the main report parameter. Link the sub to the main report by moving {?Year} to the right and then using the dropdown in the lower left of the linking screen to select the {?Year} parameter from the sub.

Then create a formula {@prevyear) like this in the subreport->field explorer->formula editor:

stringvar array x := split({?Year},"/");
numbervar yr1 := val(x[1])-1;
numbervar yr2 := val(x[2])-1;
stringvar y := totext(yr1,0,"")+"/"+totext(yr2,0,"")

In the record selection area, use a selection formula like this:

{table.stringyears} = {@prevyear}

...where {table.stringyears} is the field that displays like 2004/2005.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top