Alteryx Designer Desktop Discussions

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

Convert day name to day number

b_sab
5 - Atom

I have fields holds day name like "Saturday" or "Wednesday".. etc 

I need to convert it to day number, so "Saturday" becomes 6 and Wednesday becomes 3.. etc 

 

I was able to do the opposite, convert day number to day name, but not the vice versa. 

 

what would you suggest ?

6 REPLIES 6
atcodedog05
22 - Nova
22 - Nova

Hi @b_sab 

 

The easiest and straight forward way would be to write an If else condition block. Like below

 

 

IF [Date Weekday]="Sunday" THEN 7
ELSEIF [Date Weekday]="Monday" THEN 1
ELSEIF [Date Weekday]="Tuesday" THEN 2
ELSEIF [Date Weekday]="Wednesday" THEN 3
ELSEIF [Date Weekday]="Thursday" THEN 4
ELSEIF [Date Weekday]="Friday" THEN 5
ELSEIF [Date Weekday]="Saturday" THEN 6
ELSE Null() ENDIF

 

 

DateTimeParse doesnt seem to work on weekdays to convert to date and back to week number.

 

Hope this helps 🙂

Qiu
20 - Arcturus
20 - Arcturus

@b_sab 
Tried a another approach without conditional statement.1020-b_sab.PNG

Amarendra
10 - Fireball

The proposed solutions work great, for all your future data-related tasks you can download the Abacus for some more flexibility - https://community.alteryx.com/t5/Engine-Works/An-Overview-of-the-Alteryx-Abacus-Add-In/ba-p/398982

b_sab
5 - Atom

Thanks. the problem is i have the values in fields and not planning to create new rows. was looking if there is a formula to do that. might need to stick with IF ELSE solution

atcodedog05
22 - Nova
22 - Nova

Hi @b_sab 

 

Even i looked it to check is there a way Wednesday can be converted to a date and then a week day number.

Using DateTimeParse but seems like only DateTimeFormat can handle weekdays but DateTimeParse doesnt handle weekdays. Apparently 

TheOC
15 - Aurora
15 - Aurora

Hi @b_sab 

Very similar to @atcodedog05's if/else statement, but I managed with a switch/case, which I personally much prefer for use-cases like this as I find them cleaner, but result is the same:

 

TheOC_2-1603207619867.png


Hope this helps!

 


Bulien
Labels