Bring your best ideas to the AI Use Case Contest! Enter to win 40 hours of expert engineering support and bring your vision to life using the powerful combination of Alteryx + AI. Learn more now, or go straight to the submission form.
Start Free Trial

Alteryx Designer Desktop Discussions

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

Malformed IF Statement

dougop
7 - Meteor

 Hello,

 

I am trying to write a multiple level IF statement and am getting a malformed statement.  I am not sure where the problem is as I believe that the syntax is correct.  Let me know what you all think!

7 REPLIES 7
DataNath
17 - Castor
17 - Castor

Hey @dougop there's a couple of things I'd check here:

1) Is your [Date Difference Hire] definitely a numeric data type? If it's a string it'll error like you're seeing. You can either change this in a Select tool (before the Formula), or, f you're making this field in a Formula tool then you can just change it in the 'Data Type' dropdown underneath the expression box.

2) On line one, where you have 'THEN [Review]' - are you meaning to reference a field here or should this be "Review"?

JamesCharnley
13 - Pulsar

Hi @dougop 

 

My best guess is that, given where the formula is saying there's an error, you've got the wrong data type for [date diff term]. Check that it's not a string and then that might work.

Sebastiaandb
12 - Quasar

@dougop 

 

What kind of datatype is [date diff term] ? I believe it should be numerical and it isn't :-).


Greetings,

 

Seb

dougop
7 - Meteor

Hey everyone - yes both columns are numeric as they have been through a "datetimeparse"  tool.  See screenshot for the formula showing as fine until I put the ending "ELSE" and  "ENDIF" in

DataNath
17 - Castor
17 - Castor

That's normal behaviour @dougop - the expression won't error until you end it. See here, I have a string value going in that works fine:

 

DataNath_0-1668006154510.png

 

Until I end the statement:

 

DataNath_2-1668006177157.png

 

DataNath_1-1668006166259.png

 

If you hit the blue Metadata tab in the bottom left, is it definitely not a string going into the Formula tool? As this erroring is consistent with this.

 

DataNath_3-1668006215129.png

 

Edit: Even though it *appears* numeric, coming out of a DateTime tool, the result is actually a string (radio button select is Date/Time format to string) so you'll need to make it numeric:

 

DataNath_0-1668006510964.pngDataNath_1-1668006518827.png

Sebastiaandb
12 - Quasar

@dougop ,

 

Mmmm, can you make a screenshot of the metdata going into the formula tool?

Sebastiaandb_0-1668006254099.png

 

Would be nice to see what types they are :-).

 

Greetings,


Seb

JamesCharnley
13 - Pulsar

My understanding is that running it through a datetimeparse will still leave it as a string. Check my screenshot in the formula that's doing the same as yours when stored as a string:

 

JamesCharnley_0-1668006240102.png

JamesCharnley_1-1668006249159.png

 

You can wrap the diff term in ToNumber() too if you'd prefer

 

Labels
Top Solution Authors