Alteryx Designer Desktop Discussions

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

Month name based on number

JustynaMZ
7 - Meteor

What is incorrect with my formula?

if [Report month]=1 then 'January' elseif [Report month]=2 then 'February' elseif [Report month]=3 then 'March' elseif [Report month]=4 then 'April' elseif [Report month]=5 then 'May' elseif [Report month]=6 then 'June' elseif [Report month]=7 then 'July' elseif [Report month]=8 then 'August' elseif [Report month]=9 then 'September' elseif [Report month]=10 then 'October' elseif [Report month]=11 then 'November' elseif [Report month]=12 then 'December' else [Report month] endif

6 REPLIES 6
phottovy
13 - Pulsar
13 - Pulsar

Hi @JustynaMZ ,

 

You can use the following formula to extract the full month name from a date column which could save you the trouble of writing a long if statement: 

 

DateTimeFormat([date_field], '%B')

 

 

I find the link below very useful when using the different date functions.

DateTime Functions | Alteryx Help

cjaneczko
13 - Pulsar

Think you are overcomplicating this. A formula tool with the below will do what you are looking once the column is formated to the correct DateTime.

 

DateTimeFormat([Report month],'%B')
cjaneczko
13 - Pulsar

If the column you are using isnt in a Date/Time format and just a string number of 1-12 you can also use the following.

 

DateTimeFormat(DateTimeParse(ToString([Report month]),"%m"),"%B")
JustynaMZ
7 - Meteor

Thanks, and if I want to receive previous month (i.e. if I have 4 as April and for 4 I want to receive 'March'?

RobertOdera
13 - Pulsar

Hi, @JustynaMZ 

 

If I understand your question correctly:

 

1. If you have a field, [Report month], that is Type = Text or String, with values ranging from 1-12, then do the below

 

If [Report month]='1' then 'January'

elseif [Report month]='2' then 'February'

elseif [Report month]='3' then 'March'

elseif [Report month]='4' then 'April'

elseif [Report month]='5' then 'May'

elseif [Report month]='6' then 'June'

elseif [Report month]='7' then 'July'

elseif [Report month]='8' then 'August'

elseif [Report month]='9' then 'September'

elseif [Report month]='10' then 'October'

elseif [Report month]='11' then 'November'

elseif [Report month]='12' then 'December'

else 'Fix Me'

endif

 

2. If your [Report month] field is an integer or double or number, you can use ToString([Report month]) to make it a string or text  AND then use the formula in 1 above. OR, you can keep the number format and alter the formula in 1 above by changing '1' to 1, i.e., do not represent the month as text.

 

-If you have a Date field in your data, you may use the Date Parse Tool or the date format formulas in a Formula Tool.

- I hope you find this helpful. Cheers!

 

RobertOdera
13 - Pulsar

Hi, @JustynaMZ 

 

If you have a date field, use DateTimeAdd([Date field], -1, "month") to get the month before the current month

It might be more helpful if you could share a sample and your desired result - and the community will help you😎

Labels