community
cancel
Showing results for 
Search instead for 
Did you mean: 

Alteryx designer Discussions

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

Replacing Month number with month name

Asteroid

I have a data set with the field mth with values 1 through 12. I changed the data type to a string.

I'm trying to replace the mth number with a month name, so 1=Jan, 2=Feb and so on.

I've tried the switch, IIF and If then else formulas on current field and they change the mth field name to Jan. not what i'm after

the formula editor does not recognize my mth field as a variable.

Highlighted
Pulsar

Switch should work for you:

 

Switch([mth],Null(),1,"Jan",2,"Feb",3,"Mar",4,"Apr",5,"May",6,"Jun",7,"Jul",8,"Aug",9,"Sep",10,"Oct",11,"Nov",12,"Dec")

 

In the above I'm using the "mth" field as a numeric --- if it's a string, wrap each of the numbers in quotes.

 

What are you getting as a result, if any?  Can you post some screenshots and/or sample data?

You can hardcode the month number,names into a text input tool and then use Alteryx's find and replace tool to either replace your numerical month field or to just add a new column with the month name without getting rid of the numerical field.  If you want to store the month number as a string, make sure that after creating the text input tool you use a select node to convert the month number into a string there as well.

Alteryx Certified Partner
Alteryx Certified Partner

@parria1,

 

There are many options and the following is just one of them:

 

datetimeformat("2000-"+padleft(tostring([mth]),2,"0")+"-01","%b")

Because you can read any given date and output the month "%b" as the abbreviated month name, I chose this method because I'm lazy.

 

Cheers,

Mark

Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and reboot. Order shall return.
Asteroid

When I do this, the result is the values of my mth field are changed to null.

 in reply to @danrh

Pulsar

Instead of replacing the field in the Formula tool, create a new field.  I don't have your excel file so I can't test it out, but I would guess it's because you're outputting a string to a numeric field.

Asteroid

perfect, thank you @MarqueeCrew

Asteroid

@danrh thank you, this also works now when I output to new column using the formula tool.

Meteor

Thank you so much for the solution. How would you add year to the output by using same formula? Example: Apr 2017

 

Cheers,

John

Asteroid

connect a formula tool to the one used for the formula output to your month field

datetimeformat("2000-"+padleft(tostring([mth]),2,"0")+"-01","%b")

and concatenate the year and month and output to a new field

[mth]+" "+[yr]

 

where mth and yr are fields in your data

Labels