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

Formula using variables 1

Status
Not open for further replies.

skurkal

IS-IT--Management
Apr 6, 2005
37
US
Hi All,

I am using CR XI. I have a sql query that returns summed up values (4 rows to be exact)

Item Sum
---- ---
A 10
B 20
C 40
D 5

Now using crystal I have to show these values up on the report header, in a pretty format.

So I have created formulas with variables that store these values. The formula is :


WhilePrintingRecords;
NumberVar TotalA:= 0;

While not OnLastRecord
Do

If {Command.Item} = 'A'
Then TotalA := TotalA + {Command.Sum}

I was planning to do the same for each Item (A, B,C, D) but this formula is thowing an error "A loop was evaluated more than the maximum number of times allowed".

How do I get around this issue?

Thanks in advance for any help,
Sumitra.
 
You won't be able to loop through all the records in one run of a formula.

I would suggest creating four formulas, one for each Item type:

//@Item_A
if {Command.Item} = "A"
then {Command.Sum}
else 0

//@Item_B
if {Command.Item} = "B"
then {Command.Sum}
else 0

//@Item_C
if {Command.Item} = "C"
then {Command.Sum}
else 0

//@Item_D
if {Command.Item} = "D"
then {Command.Sum}
else 0

You can then insert a summary field off each formula and place them in the report header.

~Brian
 
Or you could insert a crosstab that uses item as the row or column field, and then use the sum as the summary field.

-LB
 
Thanks for your reply. This worked very well. I had created the same formulas before, but I did not create a summary field for each formula. When I tried to use the fomula as is, it would give me results for only one row, the rest would be 0. What is the explaination behind the using a summary field?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top