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

Simplify Set Variable formula

Status
Not open for further replies.

Flopper

Technical User
Jan 19, 2001
140
AT
[Crystal Reports v8.5]

Greetings,

Is it possible to simplify the following formula:
-----------------------------------------------------------
Whileprintingrecords;

Global numbervar Mth1_CallRcvdCt:= If Month({@Date Mth1 Start})=Month({ACD_STATS.Date}) then {ACD_STATS.Call_Rcvd} else Mth1_CallRcvdCt;
Global numbervar Mth2_CallRcvdCt:= If Month({@Date Mth2 Start})=Month({ACD_STATS.Date}) then {ACD_STATS.Call_Rcvd} else Mth2_CallRcvdCt;
Global numbervar Mth3_CallRcvdCt:= If Month({@Date Mth3 Start})=Month({ACD_STATS.Date}) then {ACD_STATS.Call_Rcvd} else Mth3_CallRcvdCt;

------------------------------------------------------------
The formula is used to retrieve values for a manual cross-tab. An automated cross-tab would produce the relevant figures but for various reasons this is not the method i seek. Is it possible to declare a variable using a formula as this may help?!?

Thanks
 
It looks pretty simple the way you have it. The only issue is if you have a lot of them, right?

You could experiment with some arrays and a for loop. If what you are trying to do is change your

Mth1_CallRcvdCt:= ...

into

MthX_CallRcvdCt:= ...

You'd have to make it


Global numbervar array Mth_CallRcvdCt;
local numbervar x;
for x := 1 to 10 do
(
Mth_CallRcvdCt[x]:= ...
);


or something like that.

I also don't know that it won't barf when you get to the cross-tab stage. But I'd try it just to see if it worked, myself. I'm not sure how "WhilePrintingRecords" would affect the results so I'd try it with and without.

I'm not sure if arrays and for loops are different in 8.5, since I haven't used that in a while and I never did stuff like this with 8.5 anyway.

scottm.

 
Thanks Scott,

I'll have a try and see if i can improve on this.

 
No need to use the word 'global'. All variables are global by default.

Software Sales, Training, Implementation and Support for Macola, eSynergy, and Crystal Reports
 
You would be much better off creating separate formulas per month so that you can insert summaries on them, as in:

//{@Jan}:
if Month({ACD_STATS.Date}) = 1 then {ACD_STATS.Call_Rcvd}

//{@Feb}:
if Month({ACD_STATS.Date}) = 2 then {ACD_STATS.Call_Rcvd}

You would right click on each formula and insert a summary (sum) and then suppress the detail section. If you have a group (the equivalent of a crosstab row field), you would insert summaries at the group and grand total level.

If you want to have a date parameter for the beginning month, then you could use formulas like:

//{@month1}:
if Month({ACD_STATS.Date}) = month({?startdate}) then {ACD_STATS.Call_Rcvd}

//{@month2}:
if Month({ACD_STATS.Date}) = month(dateadd("m",1,{?startdate})) then Month({ACD_STATS.Date})

etc.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top