Nested if statements

154
3
Jump to solution
09-25-2018 06:19 AM
Highlighted
New Contributor II

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

Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
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
Highlighted
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

Highlighted
New Contributor II

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 ! 

Reply
0 Kudos
Highlighted
MVP Esteemed Contributor

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

Reply
0 Kudos