General Discussions

Discuss any topics that are not product-specific here.
SOLVED

Need help with IF, THEN, ELSE multiple statement

msalas0308
5 - Atom

Hello,

I am having a problem with a conditional statement (IF c THEN t ELSE f ENDIF), below is my formula. I am having a hard time with the last step. it gives me the "Invalid type in operator >=" error. 

 

I am trying to change the Week numbers to months, so IF Week No is less then 6, change it to Jan. If Week number is between 6 and 9, change to Feb, and so on and so forth. But the last ELSEIF is giving me an error and I'm not sure how to fix that. 

 

IF [Week No.] < 6 THEN "Jan"
ELSEIF [Week No.] >= 6 AND [Week No.] < 9 THEN "Feb"
ELSEIF [Week No.] >= 10 AND [Week No.] < 13 THEN "Mar"
ELSEIF [Week No.] >= 14 AND [Week No.] < 17 THEN "Apr"
ELSEIF [Week No.] >= 18 AND [Week No.] < 22 THEN "May"
ELSEIF [Week No.] >= 23 AND [Week No.] < 26 THEN "Jun"
ELSEIF [Week No.] >= 27 AND [Week No.] < 31 THEN "Jul"
ELSEIF [Week No.] >= 32 AND [Week No.] < 35 THEN "Aug"
ELSEIF [Week No.] >= 36 AND [Week No.] < 39 THEN "Sep"
ELSEIF [Week No.] >= 40 AND [Week No.] < 44 THEN "Oct"
ELSEIF [Week No.] >= 45 AND [Week No.] < 48 THEN "Nov"
ELSEIF [Week No.] >= 49 THEN "Dec"
ELSE ""
ENDIF

 

msalas0308_1-1649787984503.png

 

 

msalas0308_0-1649787959860.png

 

msalas0308_2-1649789002425.png

 

7 REPLIES 7
Luke_C
17 - Castor

Hi @msalas0308 

 

Can you confirm the data type of the  'Week No.' field is numeric?

Qiu
21 - Polaris
21 - Polaris

@msalas0308 
just as @Luke_C mentioned, if the data type of the  'Week No.' field is numeric, then it works. but thlatter < should be <=.

And there is a not so brutal way, and more accurate, since the week number to Month Relation is not fixed for each year.

https://community.alteryx.com/t5/Alteryx-Designer-Discussions/Date-Time-Parse-from-year-and-week-num...

0414-msalas0308-01.PNG0414-msalas0308-02.PNG

msalas0308
5 - Atom

I knew it was something simple lol thank you @Luke_C

msalas0308
5 - Atom

Yea, I figured it out from @Luke_C original response. Thank you for the help as well. 

Qiu
21 - Polaris
21 - Polaris

@msalas0308 
Maybe I suggest you check the answer from me without the conditional statement?
it is more dynamic and accurate way, I believe.

msalas0308
5 - Atom

@Qiu That worked better, thank you. 

brianfia
8 - Asteroid

Is there a reason why you are using Less than operator (<) instead of Less than Equal (<=) operator? Just curious why you would want to mark  the week numbers with those values with blank space? 

Thank You,

B

Labels