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

Problems with multiple if then else formula 1

Status
Not open for further replies.

twkyoscr

Technical User
Aug 29, 2001
22
US
Have a very simple formula(or so I thought), I need to compare two months from different years so I created the following:
If {@Month Hired} = 9 then if {@Year Hired} = 2001 then "14- September '01" else "2 - September '00"else
"Error"

I have tried "if then if" and "if and if" statements, parentheses after the first then. All return no data or error. Any suggestions would be helpful for multiple "if then else" or "if and" formulas. Thanks!
 
I find it helps to add comments to your formulas and to indent the if statements. Your formula would look like this:
Code:
If {@Month Hired} = 9 then 
   // Hired in September
   if {@Year Hired} = 2001 then 
      // Hired in Sept, 2001
      "14- September '01" 
   else 
      // Hired in September from some other year
      "2 - September '00"
else
   // Not hired in September
   "Error"

From this version of your formula you can see that you will get an 'error' result when September wasn't the hired month. Is that what you wanted? Steve Phillips, Crystal Consultant
 
Hi ... I go one step farther than Steve and wrap parenthesis around sections to isolate them...also it allows you to have multiple statement IF blocks

If {@Month Hired} = 9 then
( if {@Year Hired} = 2001 then
"14- September '01"
else
"2 - September '00";
)
else
"Error";

Jim
 
Hi,

if you are using formulae within a formula, you should define the evaluation order.

ie. at the start of the formula you need...

evaluateafter({@Month Hired});
evaluateafter({@Year Hired});

Hth,
Geoff
 
Steve, bless you that worked perfectly! Thanks to all that gave suggestions. I will keep them for future use!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top