Nested if statements

772
3
Jump to solution
09-25-2018 06:19 AM
AJM
by
New Contributor III

I am trying to assign a label based on a size range but it is not working. Here is the stament I am using.

if(${c_lenght_cal} <= 5, "Hatchling", (if${c_lenght_cal} >5 and ${c_lenght_cal} <=10, "Post-hatchling",(if${c_lenght_cal} >10 and ${c_lenght_cal} <=60, "Juvenile", (if${c_lenght_cal} >60 and ${c_lenght_cal} <=92, "Subadult", "Adult"))))

What am I missing?

Thanks

0 Kudos
1 Solution

Accepted Solutions
StephenM
Occasional Contributor II

It looks like you have the parentheses within the statement on the wrong side of the ifs.

This worked for me:

if(${c_length_cal} <= 5, "Hatchling", if(${c_length_cal} > 5 and ${c_length_cal} <= 10, "Post-hatchling", if(${c_length_cal} > 10 and ${c_length_cal} <=60, "Juvenile", if(${c_length_cal} > 60 and ${c_length_cal} <= 92, "Subadult","Adult"))))

For what it's worth, I think you might be able to shorten this statement as well. I don't think you need the > statements, since the previous <= statement will have already evaluated to true.

if(${c_length_cal} <= 5, "Hatchling", if(${c_length_cal} <= 10, "Post-hatchling", if(${c_length_cal} <=60, "Juvenile", if(${c_length_cal} <= 92, "Subadult","Adult"))))

View solution in original post

3 Replies
StephenM
Occasional Contributor II

It looks like you have the parentheses within the statement on the wrong side of the ifs.

This worked for me:

if(${c_length_cal} <= 5, "Hatchling", if(${c_length_cal} > 5 and ${c_length_cal} <= 10, "Post-hatchling", if(${c_length_cal} > 10 and ${c_length_cal} <=60, "Juvenile", if(${c_length_cal} > 60 and ${c_length_cal} <= 92, "Subadult","Adult"))))

For what it's worth, I think you might be able to shorten this statement as well. I don't think you need the > statements, since the previous <= statement will have already evaluated to true.

if(${c_length_cal} <= 5, "Hatchling", if(${c_length_cal} <= 10, "Post-hatchling", if(${c_length_cal} <=60, "Juvenile", if(${c_length_cal} <= 92, "Subadult","Adult"))))

AJM
by
New Contributor III

Stephen

Thanks I just figure out the parentheses and got it working a little while ago also.

I like the idea of shortening the statement so I will give that a try ! 

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

If Stephen's suggestions work for you, please mark his comment as the answer to close out this question.

0 Kudos