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

Writing a formula with multiple conditions

Status
Not open for further replies.

jstoehner

Technical User
Oct 20, 2006
18
US
I am pretty much a beginner a writing formulas. For my crystal report, I need to write a formula that tests multiple conditions and selects the right {tabe.field} based on the test.

What is the basic syntax for something like -->
If A and B then X
else if A and C then Y
etc.
 
Is this what you want?

If {table.state} = "Calif" and {table.Amount} >= 1000.00 then "Big Spender" else
If {table.state} = "Calif" and {table.Amount} < 1000.00 then "Small Spender"

MrBill
 
It depends upon whether you are testing the results of one field or multiple fields in the same row. Try using actual field names and show some sample data.

-LB

 
I was about to post a very similar question. I'm also trying to write a formula with multiple conditions and I may be looking for the same answer.

I'm pulling records from a stored proc with two bit fields. If column a equals 1 I want the row on the report red. If column b equals 1, I want the row blue. If both are 1 I want the row green. My formula is as follows:

If (({Field.a} = 1) and ({Field.b} = 1)) then
Formula = crGreen
else if (Field.b} = 1 then
Formula = crBlue
else if {Field.a} = 1 then
Formula = crRed
else
Formula = crBlack
end if

I assume I'm missing something very obvious here.

 
You're using Crystal Basic syntax, most don't/

The age old language is more a derivative of C, and you would use:

If {Field.a} = 1 and {Field.b} = 1 then
crGreen
else
if {Field.b} = 1 then
crBlue
else
if {Field.a} = 1 then
crRed
else
crblack

-k
 
Thanks, I'll give it a try. Oh, and I apologize for hijacking the thread jstoehner.
 
Hi,

I have also this problem where I have to solve the following problem.
In each record I have to check 3 times the value of a pair of 2 colums A and B, D and C, E and F

If A = xxx and B = yyy then set variable x value to 1 else 0
If C = xxx and B = yyy then set variable y value to 1 else 0
If D = xxx and F = yyy then set variable z value to 1 else 0

After this I have to sum variables x, y and z from each record but if A AND C = "blablabla" then make only the sum of A and D...

Since i'm not a programmer I really don't see how to get ther at the moment so if anyone shoul know how to do this, you're welcome to share the info.

Kind regards and thanks anyway.

Chris
 
chrisseke, please start a new thread. Also, please identify field names and results, and show sample data, instead of using abstract "bla" type descriptions. i could follow what you meant up to this sentence, so you need to clarify (in your new post):

After this I have to sum variables x, y and z from each record but if A AND C = "blablabla" then make only the sum of A and D...
 
By the way, I meant to thank the responders to my initial post. As I said, I'm pretty much a beginner and did not realize that you combine your conditions with "and" before the "then" statement. I know....duh! Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top