Alteryx Designer Desktop Discussions

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

Formula tool

Ainekeenan99
5 - Atom

Hi 

 

Im trying to write the following into the formula tool - if [bmi] > 24.9 THEN "1" elseif [bmi] < 18.5 THEN "2" else "3" endif

it keeps coming up with the following error - Error: Formula (5): The formula "bmi" resulted in a string but the field is numeric. Use ToNumber(...) if this is correct. (Expression #4)

anyone able to help me?

7 REPLIES 7
Assaf_m
11 - Bolide

try this, removing the double-quotes.

 

if [bmi] > 24.9 THEN 1 elseif [bmi] < 18.5 THEN 2 else 3 endif

Ainekeenan99
5 - Atom

i removed the quotation marks and it worked but only showing 1 and 3 on data not recognize 2  

atcodedog05
22 - Nova
22 - Nova

Hi @Ainekeenan99 

 

As your error message is saying [bmi] is a string datatype but you need to numeric to do numeric compare. 
As the error message suggests you need to use ToNumeric() function.

 

Formula

 

if ToNumber([bmi]) > 24.9 THEN "1" 
elseif ToNumber([bmi]) < 18.5 THEN "2" 
else "3" endif

 

Workflow:

atcodedog05_0-1605442165804.png

If you are facing please reply on the same post i will help you out.

 

Hope this helps 🙂


If this post helps you please mark it as solution. And give a like if you dont mind 😀👍

Ainekeenan99
5 - Atom

when i put that in it comes up error, when i use this --- if [bmi] > 24.9 THEN 1 elseif [bmi] < 18.5 THEN 2 else 3 endif

there is no error it just will not recognize 2 , so all my data is either 1 or 3 

 

atcodedog05
22 - Nova
22 - Nova

Hmm thats great

 

Can you check you data to see if there is any value below 18.5 so that it will be tagged as 2

You can use a filter tool for this.

 

If you are still facing the issue. You can try this once

if ToNumber([bmi]) > 24.9 THEN 1 
elseif ToNumber([bmi]) >= 18.5 THEN 3 
else 2 endif

 

If you are still facing issue share me a snapshot where you think value should have been 2.

 

Will be happy to help 🙂

Ainekeenan99
5 - Atom

thank you for your help 🙂 

atcodedog05
22 - Nova
22 - Nova

Happy to help 🙂 @Ainekeenan99 

 

Cheers and Happy Analyzing 😀

Labels