Join the Alteryx Community’s Maveryx Summer Cup event! Compete, network with others, and earn your gold through a series of challenges from July 24th to August 11th. Learn more about the event here.

Alteryx Designer Desktop Discussions

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

IF Statements for Tenure

tkaufman
Meteoroide

I am trying to create groups for different tenure categories, but I keep getting an error on my IF statements to create the groups.  I have tried multiple iterations to fix this, but below is the most recent. 

 

I get an error saying "Error: Formula (3): Parse Error at char(61): Malformed If Statement (Expression #1)"  I'm new to Alteryx so any help would be greatly appreciated! 

 

IF [Tenure]>'4' AND [TENURE]<'13' THEN "4-12 MONTHS"
ELSE IF [Tenure]>'12' AND [TENURE]<'25' THEN "13 - 24 MONTHS"
ELSE IF [Tenure]>'24' THEN "25 + MONTHS"
ENDIF

7 RESPOSTAS 7
binuacs
Arcturus

@tkaufman updated your formula

image.png

rzdodson
Quasar

 

@tkaufman there are two recommendations that I would make for you:

  1. Change your tenure field to be  a numeric field - this will assist Alteryx in better determining how associates should be bucketed.
  2. Add an  else statement following your last elseif - this will correct the error you are receiving while also creating a built-in tester value (i.e. all others that fall outside of your defined buckets will just null out.

Final formula will look like this following the changes.

 

 

IF [Tenure]>4 AND [TENURE]<13 THEN "4-12 MONTHS"

ELSEIF [Tenure]>12 AND [TENURE]<25 THEN "13 - 24 MONTHS"
ELSEIF [Tenure]>24 THEN "25 + MONTHS"

else null()
ENDIF

 

 

 

EDIT: @binuacs beat me to the punch! :D

cjaneczko
Pulsar

The issue with your statement is the quotes around the numbers. Quotes are not used for Numeric fields only string fields. Remove the quotes or change your Tenure to a String type. Also you dont have a final Else before the endif. Need to add Else Null() or Else ' '.

Raj
Aurora

So, the If statement have IF,then,else and Endif 
but your statement is missing else part so you can correct it by adding the else condition.

as suggested by pears you can add Null or any value you desire.

A simple solution to this problem is to remove the quotation marks from your comparison formula. Additionally, it is advisable to insert an "ELSE" statement before the "ENDIF."
Thanks

 

Sapna Gupta
tkaufman
Meteoroide

Sorry it took so long to reply.  This worked PERFECTLY!  Thank you so much.

tkaufman
Meteoroide

You are absolutely correct!  I could not figure out why when I was trying to recreate it, it wasn't working.  And I was missing that last else. Thank you so much for the help!

Rótulos