Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

IF Then ELSEIF Statement Error: Invalid Type in Operator

kristinat
5 - Atom

HI,  I have 5 workflows ending with 5 basic tables +  Union.  To identify each table, I added a Record Id tool.  Each Table is then Numbered 1-5 per the Record ID tool.  I was using the Formula tool after my new column as such to rename my 1-5 Tables:

 

IF [Blacklist] = "1" then "Fax"
ELSEIF [Blacklist] = "2" then "Phone"
ELSEIF [Blacklist] = "3" then "Email"
ELSEIF [Blacklist] = "4" then "Address"
ELSEIF [Blacklist] = "5" then "Bank"
ELSE "Blacklist"
endif

 

However, I am getting the Invalid Type in Operator error.  Is it because I have numbers in the formula?  My Data Type is showing as a V_WString. 

The Record ID Type is currently set at Int64 but I had played around and configured it to String and still didn't work.


Thoughts?  Probably something silly I'm missing as I've only been using Alteryx <1 year. 


Thank you!

Kristina

 

 

6 REPLIES 6
TheOC
15 - Aurora
15 - Aurora

Hi @kristinat ,
This error is when you are testing for a string, but are passing in an integer (or other type of variable). I have attached a sample workflow with a very simplified example to show you what I mean, but when you are testing (IF [Blacklist] = "1" then "Fax") you need to remove the speech marks - IF [Blacklist] = 1 then "Fax"

So that it knows to test for an integer.

Hope this helps!


Bulien
Qiu
20 - Arcturus
20 - Arcturus

@kristinat 
Just add to @TheOC , the single or double quotation indicates you are comparing something other than numeric.
There are some ways to change data types, such Select, ToNumeric, ToString and the latter is handy since they can used in Formula Tool.
Here is a post you migh want to take a look.
https://community.alteryx.com/t5/Alteryx-Designer-Knowledge-Base/Alteryx-Data-Types-101/ta-p/27580

TheOC
15 - Aurora
15 - Aurora

Good point @Qiu, there would be two ways to fix this solution (well, potentially many more), attached is examples of the different ways!



Bulien
rajatsadan
8 - Asteroid

Hi @kristinat ,

 

Please find the workflow for the solution. 

I believe the issue you might be facing is that the Record ID is still set to Int64. The new column is default set to string format (V_string) and therefore you would need to keep it in string format itself as the output will be a string(Eg. Phone, Fax etc).

 

In this case, you can convert the RecordID(which is named as Blacklist) to V_WString format using the 'Select Tool' and then run the formula. 

 

Also, since only 5 rows are present, you can modify the statement as follows:

IF [Blacklist] = "1" then "Fax"
ELSEIF [Blacklist] = "2" then "Phone"
ELSEIF [Blacklist] = "3" then "Email"
ELSEIF [Blacklist] = "4" then "Address"
ELSE "Bank"
endif

which by default sets record ID no.5 to Bank. 

 

Hope this helps !!

 

kristinat
5 - Atom

That did it!!  Is "I love you" too strong of a thank you?  Two days later and it was because I had "" around the integer.  🙂

Thanks, pal.   @TheOC , You rule at life.

 

KT

TheOC
15 - Aurora
15 - Aurora

@kristinat not too strong of a thank you as long as you're talking about Atleryx 😉 !
Really glad I could be of assistance and really glad its worked out!

Have a great rest of your week,


Bulien
Labels