Mike
Mike

Reputation: 743

Crystal report dynamic formula name

Here is what I have. I have 15 unique formulas named Week1, Week2, ... Week15. I would like to be able to take a parameter name, MYCount, and use that to loop through the records and sum them. So if MyCount is equal to 3, the loop would sum Week1 + Week2 + Week3. I know how to create a loop, but I cannot figure out how to build the formula name dynamically. Here is what I have so far: (I am using Crystal Xi)

 Whileprintingrecords;
 local NumberVar i := {?MyCount}
 For i := 1 To (MyCount-1) Do (
    i = {@Week & "i"} + i
 );
 x

Upvotes: 0

Views: 1698

Answers (3)

user359040
user359040

Reputation:

If you are using your @Weekn formula fields so that you can summarise by date across the page, then have you considered using Crystal's Crosstab functionality instead?

Upvotes: 0

craig
craig

Reputation: 26262

I don't exactly what you are trying to do, but you may want to consider another approach.

Create a formula that will segment a field based on a date field's week number:

//{@amount}
// adjust firstDayOfWeek and firstDayOfYear parameters to match your organization's
// definition of a week
If DatePart("ww", {table.dateField})<={?Week} Then
  {table.amount}

Insert a summarized field on the formula field.

Upvotes: 0

Lee Tickett
Lee Tickett

Reputation: 6027

I think you may be over complicating. Why not just do:

Local numbervar x := 0;
If param > 0 then
 X := x + week1;
If param > 1 then
 X := x + week;
And so on...
 X;

Upvotes: 1

Related Questions