Quick Tip: Display Number as Month

Quick tip for you today! I need to do some math on months and don’t want require the users to enter a full date. I created the “Month” column as a number field, no decimals, not required, min value 1, max value 12. Now I’m able to do any calculation that I want on the month value, but my views and DVWPs display the number, and I want to be able to display it as the actual month from time to time.

Attempts:
I created a calculated column that I titled “MonthName”. Here are some quick formulas that you can use in your calculated column that will convert your 1-12 number into a month name.

=TEXT([MonthNumColumn],"mmmm") will give you “December” for a value of “12”
=TEXT([MonthNumColumn],"mmm") will give you “Dec” for a value of “12”
HOWEVER, this seemed to only return values for December and January – and they were not actually accurate.

I thought that perhaps it was because the numbers were not all 2 digit, so I created a second calculated column that I titled “MonthNN” and used this formula (I know, starting to go down the rabbit hole):
=TEXT([Month],"00")
And then adjusted the above calculated MonthName field to refer to this new calculated column. No change.

Then I attempted to use the “CHOOSE” function, but the “Month” field was not required and returned “#VALUE!” for any blank fields.

So I nested the CHOOSE function inside an IF statement, and it’s not the most elegant, but it works:
=IF(Month="","NA",CHOOSE(Month,"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"))

Enjoy!

No Responses

There are no comments.

Comments are closed.

For questions and feedback on this entry, send me an email.