I am new to the tool. I am trying to use the Formula tool to read a Substring and create a new field with the result. I am getting the error that the field is not contained in the record (Expression #2). The input field is defined as a V_String. I tried to create the new output field as a boolean and as a v_string. I get the same error either way. I tried the starts with function as well. No luck.
IF Substring([CLASS_CODE],1,5) = "43101" then 1
ELSEIF Substring([CLASS_CODE],1,6) = "439951" then 1
ELSEIF Substring([CLASS_CODE],1,6) = "439952" then 1
ELSEIF Substring([CLASS_CODE],1,6) = "439953" then 1
ELSEIF Substring([CLASS_CODE],1,6) = "439954" then 1
ELSEIF Substring([CLASS_CODE],1,2) = "65" then 1
ELSE 0
ENDIF
Any help would be greatly appreciated!
Thanks,
Jill
Solved! Go to Solution.
Hi @jillvecc
your "THEN" value is suggesting that the value is numeric so VSTRING or BOOL won't work. If you want it as a string, put the 1 in quotes. if you prefer a numeric 1, you can use the field type byte or any of the INT's.
Hope this helps!
Jimmy
I spoke too soon... I just tested on my end (v11.5) and a value of 1 (unquoted) is acceptable.
Any chance that you can share your workflow with a sample/generalized data set to investigate further?
Thank you,
Jimmy
That error is suggesting that you have 2 expressions within your formula tool. The second of which has not been told which field to target.
Go to the configuration of the Formula tool and look to see if there is a second row:
If there is click the > to expand it then the trash icon to delete
Thanks! I did have a second expression in the tool. The error is resolved, but the new column I am trying to populated based on the substring is not working. Everything is being set to zero.
My error message was resolved, but the data in the new column isn't setting the flag based on the substring. Everything is set to zero.
As a guess without seeing the data try:
IF Substring([CLASS_CODE],0,5) = "43101" then 1 ELSEIF Substring([CLASS_CODE],0,6) = "439951" then 1 ELSEIF Substring([CLASS_CODE],0,6) = "439952" then 1 ELSEIF Substring([CLASS_CODE],0,6) = "439953" then 1 ELSEIF Substring([CLASS_CODE],0,6) = "439954" then 1 ELSEIF Substring([CLASS_CODE],0,2) = "65" then 1 ELSE 0 ENDIF
Alteryx Substring uses 0 to refer to first character.
That was it!!! Thank you so much.
Thanks that worked nicely on a problem I had asked about!
Good!!!