Solved

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

Posted on 2007-12-06
7
5,311 Views
Last Modified: 2010-10-05
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

0
Comment
Question by:yzlbrmn
7 Comments
 
LVL 28

Expert Comment

by:bdreed35
ID: 20420471
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?
0
 

Author Comment

by:yzlbrmn
ID: 20420577
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}

0
 
LVL 28

Accepted Solution

by:
bdreed35 earned 500 total points
ID: 20420720
Does this work?

select {SP_Package_Coverage;1.cat}
  case 1 :{SP_Package_Coverage;1.total1}
  case 2 :{SP_Package_Coverage;1.total2}
  case 3 :{SP_Package_Coverage;1.total3}
  case 4 :{SP_Package_Coverage;1.total4}
  case 5 :{SP_Package_Coverage;1.total5}
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Expert Comment

by:randomjames
ID: 20420798
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

0
 
LVL 3

Expert Comment

by:randomjames
ID: 20420815
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.
0
 
LVL 1

Expert Comment

by:Computer101
ID: 20592617
Forced accept.

Computer101
EE Admin
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now