Link to home
Start Free TrialLog in
Avatar of yzlbrmn
yzlbrmn

asked on

Help with my crystal report - trying to use a select case

Hi, I am new to crystal reports, so please help.
I am trying to create a formula in crystal that will use 2 recordset fields (category and total), and based on the category will return a corresponding total.
There are 5 categories available.
I tried using if statement, as well as select case, but it only returns the value of the first one.

Please help.
dim amount as number
 if category=1 then
    amount =total
elseif category=2 then 
 amount =total
ElseIf category=3 Then
 amount =total
ElseIf category=4 Then
 amount =total
ElseIf category=5 Then
 amount =total
End If
formula =amount

Open in new window

Avatar of bdreed35
bdreed35
Flag of United States of America image

Can you post the actual formula you are trying to use and not pseudo code?
Your code always returns the same total fields regardless of the category value.  Is this what you want?
Avatar of yzlbrmn
yzlbrmn

ASKER

Thanks for replying - here is what I am trying to do - based on the category, i want to display an actual total. My recordset returns me 2 fields -category and total, so it looks like this:
Category1, Total1
Category2, Total2
Category3, Total3
Category4, Total4
Category5, Total5
I need to know the total for corresponding category, but insteas it only gives me the category1.
My formula looks like this:

if ({SP_Package_Coverage;1.cat} = 1) then
{SP_Package_Coverage;1.total}
else if ({SP_Package_Coverage;1.cat} = 2) then
{SP_Package_Coverage;1.total}
else if ({SP_Package_Coverage;1.cat} = 3) then
{SP_Package_Coverage;1.total}

ASKER CERTIFIED SOLUTION
Avatar of bdreed35
bdreed35
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I think you are doing it a hard way...try this;
SELECT category
CASE 1 : {first total}
CASE 2 : {second total}
CASE N : {Nth total}
DEFAULT : {default total}

Open in new window

bdreed35 beat me to finishing my response, what he has is correct and the only thing i would add is that if you want a default to handle cases that do not fit into the expected values for category then follow the form I posted above.
Forced accept.

Computer101
EE Admin