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

Error using Substring in Formula Tool

jillvecc
7 - Meteor

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

9 REPLIES 9
jrgo
14 - Magnetar

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

jrgo
14 - Magnetar

@jillvecc

 

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

jdunkerley79
ACE Emeritus
ACE Emeritus

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:

2017-10-24_19-12-56.jpg

 

If there is click the > to expand it then the trash icon to delete

jillvecc
7 - Meteor

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.

jillvecc
7 - Meteor

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.  

jdunkerley79
ACE Emeritus
ACE Emeritus

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.

 

jillvecc
7 - Meteor

That was it!!!  Thank you so much.  

Tim_at_Ford
7 - Meteor

Thanks that worked nicely on a problem I had asked about!

jillvecc
7 - Meteor

Good!!!

Labels