Excel Tips for Compensation Practitioners Weeks 5 to 8 Working with Dates Week 5 Converting Text Dates to Formatted Dates This month we will focus on working with dates. Some of the most frequently asked questions I get on Excel are around how to correct dates that won t sort correctly, how to format dates, and how to calculate formulae with dates, such as age and time in job. What is important to understand about dates is that Excel can format them in many different ways, but regardless of the formatting, the date is actually stored as a sequential number called a serial value. January 1, 1900 is stored as serial number 1, and December 1, 2008, for example, is serial number 39783 because it is 39783 days after January1, 1900. Excel stores times as decimal fractions because time is considered a portion of a day. The serial value enables Excel to sort the dates correctly. Sometimes however, when you download data into Excel from other programs, such as SAP, the date is downloaded as text, not as a date. In this case, in the formula bar (the white bar just below the tool bars), the date in the cell will have a sign in front of it, the date will not have an underlying serial number and will therefore not sort correctly. There are two ways to correct this. The first way is to use a formula in Excel called Datevalue. First insert a column to the right of the dates, and select the cell to the right of the first date. Next click the fx icon, select Date & Time for category, then Datevalue for function, click OK. Next to Date_text, enter the cell reference of the first date. Click OK. Copy this formula down the sheet. The dates will be in the form of serial numbers, but can be formatted as dates using Format Cells.
This formula will work in some cases, for example if the date is formatted like this, 1Nov08 or like this, 08/11/01. But,if for example the date looks like this, 11.01.08, a common downloading format from SAP, the formula will yield #VALUE!. In this case, the best alternative is to use a software download for Excel called ASAP Utilities. This can be downloaded, either free as an unregistered version or paid for as a registered version, from a website, www.asap-utilities.com/. It is quite safe to download, and installs itself as an additional menu on Excel. It provides many superb, time saving additional functions, one of the most useful being the date conversion function. Once you have downloaded it, select all the dates to be converted, then select ASAP Utilities Menu option No. 8 Text, then No. 8, Convert Dates. A function box will come up as shown below. Enter the format of your text date under Current date-format: and the desired format for your formatted date under Convert to:, and click OK. The dates will now be converted to a formatted date with a serial number, that can be correctly sorted and used in calculations. This is a very quick and easy method, as it converts all the dates at once, and over writes the old dates with the new correctly formatted ones.
Week 6 Formatting Dates Excel offers a huge range of options for formatting dates, but many people are not aware of this because there are only a limited number of options shown under Date when you select the Format Cells option. To appreciate the flexibility offered, you need to use the Custom option. In order to format a date, select the cell or cells with the dates in them. The dates must be Excel dates with an underlying serial number. If they are not, refer to last week s tip on how to covert them to an Excel date. Click Format, Cells in Excel 2003 or Format Cells in Excel 2007, Number, Custom. In the white box, under Type: enter the desired date format. You can use any combination of the days, months and years below with anything in between them, e.g. space, -, /. Dependent on what you enter, the date, Monday 1 December 2008 would be displayed as: Enter Shows in the cell as dd 01 ddd Mon dddd Monday mm 12 mmm Dec mmmm December yy 08 yyyy 2008
For example: ddd dd mmm yyyy Mon 01 Dec 2008 (as shown in the screen dump above) mm/dd/yy 12/01/08 mmm-dd-yyyy Dec-01-2008 mmmm yy December 08 This gives you enormous flexibility to format the date in the exact way in which you want it displayed. You can also work out which day of the week you were born on!
Week 7 Calculating Age, Length of Employment or Time in Job As HR and Compensation Practitioners, you regularly need to calculate employees age, their length of employment with the company or time in job. There is a very useful formula in Excel that does this calculation. It is a standard function in Excel 2007. but in Excel 2003 it is not standard and needs to be added in. The formula is called Yearfrac. To add the formula into Excel 2003, click on Tools, Add Ins, then check the first box for Analysis ToolPak, click OK. You will now have an additional menu option under Tools called Data Analysis, and you will have access to the Yearfrac formula. If you need to calculate age as at a certain date, e.g. as at Dec 31 2008, enter this date in a cell. If you want to calculate age as of today, enter the following formula into a cell - Today(). This will give you today s date whenever the spreadsheet is opened. To calculate age as of today or at a specific date, first insert a column to the right of the birth dates, and select the cell to the right of the first birth date. Next click the fx icon, select Date & Time for category, then Yearfrac for function, click OK.
Next to Start_date, enter the cell reference of the first birth date. Next to End_date, enter the cell reference of the cell with the today() formula or the specific desired date in it. Make the End date cell absolute, i.e. put dollar signs in front of the cell and row reference. An easy way to do this is to press the F4 key. This is important, as the formula must always reference this cell as it is copied down the sheet. Leave Basis blank. Click OK. The age will now be calculated for the first employee, and you can copy this formula down the sheet. As you copy the formula, the Start dates (birth dates) will change, but the End date cell reference for today s date or a specific date will remain the same.
Length of employment or time in job can be calculated in exactly the same way, using start date with organisation or start date in job as Start date, and today or a specific date as End Date. With age or length of employment, we generally want the age or years of service rounded down. I.e. the age 40.6 should show as 40, not 41, when rounded. Length of employment of 10.8 years should show as 10 years, not 11 years, if this is to be used for leave or benefit calculations. To round the age or years of service down, insert a column to the right of the age or years calculation, and select the cell to the right of the first age or years. Next click the fx icon, select Math & Trig for category, then Rounddown for function, click OK. Next to Number, enter the cell reference of the first age or time. Next to Num_digits, enter 0.
The age or years will then be rounded down to the nearest whole number. In the example above, 30.89 has been rounded down to 30. Copy this formula down the sheet.
Week 8 Calculating Working Days Between Dates Sometimes we need to calculate the number of working days between two dates. For example, if an employee has put in a leave application, and leave is processed manually, you would want to know how many working days leave are between the start and end leave dates. You might also want to calculate employee benefits that accrue based on the number of days worked during a specific period. Excel has a formula that does this calculation, called Networkdays, but, as with Yearfrac, it is standard in Excel 2007, but not in Excel 2003 and needs to be added in. To add the formula into Excel 2003, click on Tools, Add Ins, then check the first box for Analysis ToolPak, click OK. You will now have an additional menu option under Tools called Data Analysis, and you will have access to the Networkdays formula. Before starting the calculation, check if there are any public holidays falling on work days between the start and end dates, and enter these in an array of cells. To calculate working days between two dates, click the fx icon, select Date & Time for category, then Networkdays for function, click OK.
Next to Start_date, enter the cell reference of the leave start date or the work start date. Next to End_date, enter the cell reference of the leave end date or the work end date. Next to Holidays, enter the array of cells with the public holidays in them. Make this absolute, i.e. put dollar signs in front of the cell and row references. An easy way to do this is to press the F4 key. This is important, as the formula must always reference these cells as it is copied down the sheet. Work days between the start and end dates will now be calculated for the first employee, and you can copy this formula down the sheet. As you copy the formula, the Start dates and End dates will change, but the cell reference for the public holidays will remain the same.