Alteryx Designer Desktop Discussions

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

How to use IF Function in Alteryx

RaviTeja_1001
7 - Meteor

Hi.

 

I'm new to alteryx and exploring the functions in my day to day work.

 

While i tried putting a If condition as below, there is an error which says " Error: Formula (10): Parse Error at char(93): Malformed If Statement (Expression #1)". Can any one please correct me in the code below?

 

IF SubString([F8],11,1)="I"
THEN [F32]
ELSE IF [F45]=0
THEN [F32]
ELSE (-[F32]-[F45])
ENDIF

 

Thanks in advance.

5 REPLIES 5
CharlieS
17 - Castor
17 - Castor

Hi @RaviTeja_1001 

 

The "ELSE IF" should not have a space in Alteryx expressions. Try this:

 

IF SubString([F8],11,1)="I"
THEN [F32]
ELSEIF [F45]=0
THEN [F32]
ELSE (-[F32]-[F45])
ENDIF

 

GloriousWater
8 - Asteroid

Edit: Solution was already posted.

RaviTeja_1001
7 - Meteor

HI @Charlie S

 

Thanks for your swift response. 

 

When i use the below code, there is an error highlighted as:

 

"Error: Formula (10): Parse Error at char(0): Type mismatch. String provided where a number is required. (Expression #1)"

 

Can you please help on this?

 

RaviTeja_1001_0-1589400638687.png

 

Thanks

Ravi

 

 

CharlieS
17 - Castor
17 - Castor

Sure thing.

 

It looks like your ELSE result performs an arithmetic operation on two fields: "(-[F32]-[F45])". Since numeric values are needed, you could add this conversion into the formula so you don't have the change the field types of [F32] and [F45] ahead of this:

 

(-ToNumber([F32])-ToNumber([F45]))

 

Now that this operation is valid, a numeric value will be produced. The field is a string, so we need to make sure this part of the expression outputs a string value. We can wrap this with "ToString(" to make sure a string value is output in this string field. 

 

ToString((-ToNumber([F32])-ToNumber([F45])))

RaviTeja_1001
7 - Meteor

Thank you very much. Now this is working fine. 

Labels