2014-10-07

I recently had a client requirement to send out an automated company-wide birthday greeting email whenever it was someone’s birthday.  I decided to use SharePoint Designer to create a workflow that sends an email, and then run it on a timer job that runs nightly.  This timer job would pull all employees that have a birthday that day from a SharePoint list, then fire off the workflow for each birthday found.

No problem, that sort of thing I’ve done before.  They did have one requirement that stumped me for a little bit:  They wanted in the body of the email for it to say “Happy Birthday to [employee name] on October 2nd” for example.  But if it’s the 1st, then there should be an “st” on the end of the birthday day.  Or “th” if it’s the 4th, and so on.

I explored ways to do this by setting variables in the workflow itself based on the day portion of the Date of Birth field.  Looked too complicated if even possible.  I didn’t want to write a Visual Studio workflow to handle this one requirement. So what did I do?

Calculated Columns to the Rescue

I decided to create a few calculated columns to handle the day suffix, and well as displaying the day and the name of the birthday month.  I created the following columns:

Birthday Month Name

It’s pretty easy to derive the name of the month from a particular date field using a simple formula.  The second parameter passed to the TEXT function is what tells it how to format the month, in this case it is formatting as the full month name, for example, October.

=TEXT[Date of Birth],”mmmm”)

Birthday Day

Very similar to the first example.  You will just grab the day from the date using the DAY function.

=DAY[Date of Birth])

Birthday Day Suffix

This is the tricky one.  I ended up using a combination of nested IF functions and the OR function in order to achieve the desired result.  Since a formula for SharePoint calculated columns need to be written in one line of code, you can’t do traditional if-then-else statements.  However, you can use nested IF statements, but if you have a lot of “else” clauses, it can get very messy.

=IF(OR[Birthday Day]=”11″,[Birthday Day]=”12″,[Birthday Day]=”13″),”th”,(IF(RIGHT[Birthday Day])=”1″,”st”,(IF(RIGHT[Birthday Day])=”2″,”nd”,(IF(RIGHT[Birthday Day])=”3″,”rd”,”th”)))))))

To create a calculated column, simply go into your list’s List Settings page and add a new column.  Then choose Calculated for the column type and fill out the Formula field.

Create Calculated Column

After creating my calculated columns, my list looks like this:

Calcualted Columns List

Then when creating the body of the email in SharePoint Designer, I just used the Birthday Month NameBirthday Day, and Birthday Day Suffix fields to create my text, like so:

Calculated Columns Email

Hope you find this useful!

– This article was originally published on wendy-neal.com at http://wendy-neal.com/2014/10/fun-sharepoint-calculated-columns/

About the author 

Wendy Neal

​Wendy is a senior SharePoint consultant and has great passion for all things SharePoint, including collaboration, branding, governance, evangelism, user adoption, training, and empowering power users to build their own solutions. She enjoys writing about her experiences on her blog and is also a contributing author for CMSWire.com. When she’s not neck deep in SharePoint, Wendy enjoys spending time with her family, watching the Chicago Bears and Bulls, playing with electronics/gadgets, and she is a natural health enthusiast.​​