We help IT Professionals succeed at work.

if then elseif statement question

stevenj702
stevenj702 asked
on
I created a formula field called avgodiop.  At the 'then' part of the 'if' statement it gives me the following message "a statement is expected here."  Bellow is the formula that I am trying to put together.

If isnull({ts3_IOP_.OD5_IOP}) and isnull({ts3_IOP_.OD2_IOP}) and isnull({ts3_IOP_.OD3_IOP}) and isnull({ts3_IOP_.OD4_IOP}) and not isnull({ts3_IOP_.OD1_IOP}) then {ts3_IOP_.OD1_IOP}
ElseIf isnull({ts3_IOP_.OD5_IOP}) and not isnull({ts3_IOP_.OD2_IOP}) and isnull({ts3_IOP_.OD3_IOP}) and isnull({ts3_IOP_.OD4_IOP}) and not isnull({ts3_IOP_.OD1_IOP}) then ({ts3_IOP_.OD1_IOP} + {ts3_IOP_.OD2_IOP})/2
End If

What am I doing wrong?  I tried changing the statement after the 'then' but it still gives me a error message.
Comment
Watch Question

You do not need any EndIf at the end of your statement and you need a space in  Else If (not ElseIf)

--------------------------------------
If isnull({ts3_IOP_.OD5_IOP}) and isnull({ts3_IOP_.OD2_IOP}) and isnull({ts3_IOP_.OD3_IOP}) and isnull({ts3_IOP_.OD4_IOP})
and not isnull({ts3_IOP_.OD1_IOP}) then {ts3_IOP_.OD1_IOP}
Else If isnull({ts3_IOP_.OD5_IOP}) and not isnull({ts3_IOP_.OD2_IOP}) and isnull({ts3_IOP_.OD3_IOP})
and isnull({ts3_IOP_.OD4_IOP}) and not isnull({ts3_IOP_.OD1_IOP}) then ({ts3_IOP_.OD1_IOP} + {ts3_IOP_.OD2_IOP})/2

Thanks.

Author

Commented:
I tried what rgollakota posted and it works.  Thank you.  I had to add additional elseif lines and I followed the example in the online help and I got rid of the error.  
------------------
If isnull({ts3_IOP_.OD5_IOP}) and isnull({ts3_IOP_.OD2_IOP}) and isnull({ts3_IOP_.OD3_IOP}) and isnull({ts3_IOP_.OD4_IOP}) and not isnull({ts3_IOP_.OD1_IOP}) Then
formula = {ts3_IOP_.OD1_IOP}
ElseIf isnull({ts3_IOP_.OD5_IOP}) and not isnull({ts3_IOP_.OD2_IOP}) and isnull({ts3_IOP_.OD3_IOP}) and isnull({ts3_IOP_.OD4_IOP}) and not isnull({ts3_IOP_.OD1_IOP}) then
formula = ({ts3_IOP_.OD1_IOP} + {ts3_IOP_.OD2_IOP})/2
ElseIf isnull({ts3_IOP_.OD5_IOP}) and not isnull({ts3_IOP_.OD2_IOP}) and not isnull({ts3_IOP_.OD3_IOP}) and isnull({ts3_IOP_.OD4_IOP}) and not isnull({ts3_IOP_.OD1_IOP}) then
formula = ({ts3_IOP_.OD1_IOP} + {ts3_IOP_.OD2_IOP} + {ts3_IOP_.OD3_IOP})/3
ElseIf isnull({ts3_IOP_.OD5_IOP}) and not isnull({ts3_IOP_.OD2_IOP}) and not isnull({ts3_IOP_.OD3_IOP}) and not isnull({ts3_IOP_.OD4_IOP}) and not isnull({ts3_IOP_.OD1_IOP}) then
formula = ({ts3_IOP_.OD1_IOP} + {ts3_IOP_.OD2_IOP} + {ts3_IOP_.OD3_IOP} + {ts3_IOP_.OD4_IOP})/4
ElseIf not isnull({ts3_IOP_.OD5_IOP}) and not isnull({ts3_IOP_.OD2_IOP}) and not isnull({ts3_IOP_.OD3_IOP}) and not isnull({ts3_IOP_.OD4_IOP}) and not isnull({ts3_IOP_.OD1_IOP}) then
formula = ({ts3_IOP_.OD1_IOP} + {ts3_IOP_.OD2_IOP} + {ts3_IOP_.OD3_IOP} + {ts3_IOP_.OD4_IOP} + {ts3_IOP_.OD5_IOP})/5
End If

Thanks for all of your help.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.