Let’s talk Alteryx Copilot. Join the live AMA event to connect with the Alteryx team, ask questions, and hear how others are exploring what Copilot can do. Have Copilot questions? Ask here!
Start Free Trial

General Discussions

Discuss any topics that are not product-specific here.
SOLVED

If then statement

darroyo01
6 - Meteoroid

Trying to create if then statement using the below:

 

IF [SECURITY_CLAS_CD] = 072 THEN "TIPS"
elseif [SECURITY_CLAS_CD] != "072" THEN " "
else endif

 

If it finds 072 output would be TIPS if not leave blank.  Getting the below error 

 

Parse Error at char(90): Unknown variable "endif" (Expression #1)

 

I've change it a few times but still can't figure it out.  Thanks in advance

8 REPLIES 8
griffinwelsh
12 - Quasar

@darroyo01 you need to specify the value for your else condition. For example you could use: IF [SECURITY_CLAS_CD] = 072 THEN "TIPS"
elseif [SECURITY_CLAS_CD] != "072" THEN " "
else "" endif

darroyo01
6 - Meteoroid

Thanks for reply, now its it given the following error

 

Error: Formula (15): Parse Error at char(23): Invalid type in operator ==. (Expression #1)

 

IF [SECURITY_CLAS_CD] = 072 THEN "TIPS"
ELSEIF [SECURITY_CLAS_CD] != "072" THEN " "
ELSE""
ENDIF

 

 

OTrieger
14 - Magnetar

@darroyo01 
What is the data type of [SECURITY_CLAS_CD]?
One time you are using it as if it is a number and one time as if it is a string, that is the reason that you are getting the error.
If this field is a string then in both cases 072 needs to be in quote marks, if it is a number then it should not be in a quote marks.

darroyo01
6 - Meteoroid

@OTrieger

 

Thanks I totally missed that.  It ran now, but I didn't get the expected output.  

 

IF [SECURITY_CLAS_CD] = "072" THEN "TIPS"
ELSEIF [SECURITY_CLAS_CD] != "072" THEN " "
ELSE""
ENDIF

 

I need output to show TIPS when it finds 072 and leave a blank where it doesn't.    Thanks in advance

OTrieger
14 - Magnetar

@darroyo01 
It is due to the fact that your statement is incorrect.
No need the ELSEIF part as you have 2 conditions, or Tips or blank.
Just delete the ELSEIF row
IF [SECURITY_CLAS_CD] = "072" THEN "TIPS"
ELSE ""
ENDIF

The above says if it is 075 then Tips else blank

darroyo01
6 - Meteoroid

OTrieger

 

Thank you for you continued support.  I almost there.   Now getting the following error

 

Error: Formula (15): The formula "COMMENTARY" resulted in a string but the field is numeric. Use ToNumber(...) if this is correct. (Expression #1)

 

TrueSECURITY_CLAS_CDDouble8  
TrueCOMMENTARYDouble8  
OTrieger
14 - Magnetar

This is again relating to data type. As per Alteryx COMMENTAR has numeric data type, you need to ensure that it has a string data type, any of the string types. If you will add a Select tool before the formula tool you can see and change the data type of COMMENTAR

darroyo01
6 - Meteoroid

Thank you

Labels
Top Solution Authors