Simple clear advice in plain English

Hands on: Using Excel's nested IF function

Three examples of how Excel’s IF feature can produce the results you need

Nigel Halliday has an Excel spreadsheet listing members of a junior cricket club including a column for date of birth.

Another column shows the age group they play in: under 13; 13 and 14; 15 and 16; and 17 and over.

Calculating the age group based on date of birth is easy; however, the applicable age group needs to be based on the age as of 1 September 2005. So how can you calculate each player’s appropriate age group?

One way is to use nested IF functions. Lay out your table with each player’s name in column A, date of birth in column B and the parameters of the groupings in the range: F4 to F7. Column E is left blank so Excel will recognise columns A: D as a table.

Enter the significant date, in this case 1/9/2005, in cell B1.

On the Tools menu, choose Add-ins and check the Analysis Toolpak option. This makes extra functions available including YEARFRAC. In cell C4 enter:

=YEARFRAC(B4,$B$1,1)

and drag this formula down column C. Displaying the age of each player to three decimal places in this way offers a check so you can confirm that each player is in the right group.

In cell D4 enter:

=IF(C4>=17,$F$7,IF(C4>=15,$F$6,IF(C4>=13,$F$5,IF(C4<13,$F$4))))

This formula means that if the age in cell C4 equals or is more than 17, display the contents of F7, ‘17 and over’.

If it equals or is more than 15, display the contents of F6, ‘15 and 16’. If it equals or is more than 13, display what is in F5, ‘13 and 14’.

Finally, if the age is less than 13, display the contents of F4, ‘Under 13’.

The IF function formula chugs down through the groups, filtering out the oldest cricketers at each step, and classifying the remainder. The names of the players have been entered alphabetically here.

Excel can rearrange the players into age groups and count how many are in each group.

Click anywhere in the table and, on the Data menu, choose Sort. In the dialogue box, choose DOB Descending.

Having sorted the players into chronological order, choose Subtotals on the Data menu and make entries in the dialogue box so it reads: At each change in Group, Use function Count, Add subtotal to Group, Replace current subtotals, and Summary below data. Format to taste.

Now you can produce summaries. Click in the table again and choose Group and Outline, Auto Outline on the Data menu and you’ll have a presentable and printable result.

At the top left you’ll have a choice of views: 1, 2 and 3. View 1 just shows the grand total. View 2 shows the subtotals of each group. View 3 displays the whole table.

Reader Comments

   

Add your comment

All fields must be completed. Your email address will not be displayed or used to send marketing messages.

All messages will be checked by moderators before appearing on the site.

See our Privacy Policy for more information.

Related articles

How to stay solvent using Excel

Find out how Excel can help you keep a track of your finances

Hands on: Using Excel's PMT function

Use Excel’s PMT function to help make a decision, and get to grips with matrices

Spreadsheets - Pigeon coup

Whether or not you fancy pigeons, follow Stephen Wells' advice as he homes in on how you can use spreadsheet rankings to add a useful dimension to your leisuretime activities.

Question & Answer

Q.Why are some of the keys on my keyboard doing strange...

> Read the answer

Q.Is my phone’s Bluetooth any use?

> Read the answer

Q.Can I switch boot drives so that I can work on older...

> Read the answer

Best deals on the web

img

Samsung RV520-A07

£359.98- Buy it now

img

Acer Aspire 5750G (LX.RXP02.019)

£399.99- Buy it now

img

Apple MacBook Pro (MD313B/A)

£904.37- Buy it now

Latest issue & subscription deals

Poll

Are you concerned about viruses that target mobile phones?

Jargon Buster

Computing terms explained in plain English

Restore point

A Windows backup of system files and settings.

Great shopping deals from Computeractive