Alteryx Designer Desktop Discussions

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

Error at the End of ENDIF

jmathew94
7 - Meteor

Why am I getting an error at the end of my ENDIF  Statement??

 

When i take the ENDIF  out the color shows but if i add ENDIF then it goes black. It says "Parse Error-Malformed If Statement" 

5 REPLIES 5
TimN
13 - Pulsar

What data type is set?

jmathew94
7 - Meteor

@TimN It is set to VW_String. I have tried switching to datetime and string as well with no luck.

 

Example of the result should be formatted as 10-Oct WE1, 11-Nov WE3 etc. 

dYoast
11 - Bolide

@jmathew94 

Your arguments for the DateTimeAdd are backwards.

It should be the number to subtract first.

    DateTimeAdd([Date], -1, 'months')

 

Also, I don't think you need to format DateTimeToday.  But, you appear to be missing % before d.

TimN
13 - Pulsar

Yes!  It's backwards...

 

This works - I think.

 

 

IF [Date] >=
DateTimeAdd(DateTimeAdd(DateTimeFormat(DateTimeToday(),"%Y-%m-%d"),1, "month"),-2, "day") THEN DateTimeFormat([Date],"%m-%b") + "WE5"
ELSEIF [Date] >=
DateTimeAdd(DateTimeAdd(DateTimeFormat(DateTimeToday(), "%d"), 22,"day"), -1,"day") THEN DateTimeFormat( [Date], "%w-%b") + "UE4 "
ELSEIF [Date] >=
DateTimeAdd(DateTimeAdd(DateTimeFormat(DateTimeToday(),"%Y-%m-%d"), 15,"day"), -1,"day") THEN DateTimeFormat( [Date], "%m-Xb") + "NE 3"
ELSEIF [Date] >=
DateTimeAdd(DateTimeAdd(DateTimeFormat(DateTimeToday(),"%Y-%m-%d"), 8,"day"), -1,"day")
THEN (DateTimeFormat([Date],"%m-%b") + "NE 2")
ELSE (DateTimeFormat([Date],"%m-%b") + "WEI ")
Endif

SPetrie
12 - Quasar

You are going to have better results if you compare date values to date values. Dates as strings are not going to evaluate the same way.

Your formulas need a bit of tweaking as well.

You are formatting your DateTimeToday into a string and then attempting to do an add that requires a Date/Time data type.

Also, DateTimeAdd() should be in the format of DateTimeAdd([datevalue],increment,units) but your setup is DateTimeAdd([datevalue],units,increment)

 

If [Date] is a date value, try this formula.

 

if [Date] >= DateTimeAdd(DateTimeAdd(DateTimeToday(),1,"month"),-2,"days") then DateTimeFormat([Date],"%m-%b")+"WE5"
elseif [Date] >= DateTimeAdd(DateTimeAdd(DateTimeToday(),22,"days"),-1,"days") then DateTimeFormat([Date],"%m-%b")+"WE4"
elseif [Date] >= DateTimeAdd(DateTimeAdd(DateTimeToday(),15,"days"),-1,"days") then DateTimeFormat([Date],"%m-%b")+"WE3"
elseif [Date] >= DateTimeAdd(DateTimeAdd(DateTimeToday(),8,"days"),-1,"days") then DateTimeFormat([Date],"%m-%b")+"WE2"
else DateTimeFormat([Date],"%m-%b")+"WE1"
endif

 

 

Some of the datetimeadds can probably be combined to make it look a bit less intimidating, but its more cosmetic than it is a necessity. 

 

ifstatement.PNG

Labels