Functions in Excel
Functions in Excel
Function Description
The Excel IF function tests a supplied condition and returns one result if the condition
evaluates to TRUE, and another result if the condition evaluates to FALSE.
Note that the If function will still work if the logical_test returns a numeric value. In this
case, any non-zero value is treated as TRUE and zero is treated as FALSE.
SUMIFS Function
SUMIF Function
Function Description
The Excel Sumif function finds the values in a supplied array, that satisfy a given
criteria, and returns the sum of the corresponding values in a second supplied array.
For each call to the Excel Sumif function, the range argument (to be tested against
the criteria) is either the cell range A2-A9 or the cell range B2-B9, and
the [sum_range] argument (containing the values to be summed) is the cell range C2-
C9.
Formulas: Results:
A B C A B C
1 Month Team Sales 1 Month Team Sales
2 Jan North 1 $36,693 2 Jan North 1 $36,693
3 Jan North 2 $22,100 3 Jan North 2 $22,100
4 Jan South 1 $53,321 4 Jan South 1 $53,321
5 Jan South 2 $34,440 5 Jan South 2 $34,440
6 Feb North 1 $29,889 6 Feb North 1 $29,889
7 Feb North 2 $50,090 7 Feb North 2 $50,090
8 Feb South 1 $32,080 8 Feb South 1 $32,080
9 Feb South 2 $45,500 9 Feb South 2 $45,500
10 10
11 =SUMIF( A2:A9, "Feb", C2:C9 ) 11 $157,559 - sum of cells C6-C9
12 =SUMIF( B2:B9, "North 1", C2:C9 ) 12 $66,582 - sum of cells C2 & C6
13 =SUMIF( B2:B9, "North*", C2:C9 ) 13 $138,772 - sum of cells C2, C3, C6 & C7
Note that, in the example above:
• The function in cell A13 uses the wildcard * and so finds cells in the range B2-B9 that
begin with the text string "North". This is satisfied by the values "North 1" and "North
2".
• In all three examples, the text based criteria (including the wildcard) are encased in
quotes.
Example 2
The following example shows the Excel Sumif function using critia based on numeric
values.
Formulas: Results:
A B C A B C
1 1 200 1 1 200
2 2 45 2 2 45
3 1 550 3 1 550
4 2 450 4 2 450
5 1 20 5 1 20
6 6
7 =SUMIF( A1:A5, 1, B1:B5 ) 7 770 - sum of cells B1, B3 & B5
8 =SUMIF(B1:B5, ">100" ) 8 1200 - sum of cells B1, B3 & B4
Note that, in the above spreadsheet:
SUMIFS Function
Function Description
The Excel Sumifs function finds values in one or more supplied arrays, that satisfy a set
of criteria, and returns the sum of the corresponding values in a further supplied array.
The function is new in Excel 2007, and so is not available in earlier versions of Excel.
The Sumifs function can be used to find total sales figures for any combination of
quarter, area and sales rep.
A B C D
1 Quarter Area Sales Rep. Sales
2 1 North Jeff $223,000
3 1 North Chris $125,000
4 1 South Carol $456,000
5 2 North Jeff $322,000
6 2 North Chris $340,000
7 2 South Carol $198,000
8 3 North Jeff $310,000
9 3 North Chris $250,000
10 3 South Carol $460,000
11 4 North Jeff $261,000
12 4 North Chris $389,000
13 4 South Carol $305,000
Example 1
To find the sum of sales in the North area during quarter 1:
I.e. this formula finds the sum of the values $223,000 and $125,000 (from cells D2 and
D3).
Example 2
Again, using the data spreadsheet above, we can also use the Sumifs function to find
the total sales for "Jeff", during quarters 3 and 4:
I.e. this formula finds the sum of the values $310,000 and $261,000 (from cells D8 and
D11).
COUNTIF Function
Function Description
The Excel Countif function returns the number of cells within a supplied range, that
satisfy a given criteria.
range - The range of cells that should be tested against the supplied criteria and
counted if the criteria is satisfied.
criteria - A user-defined condition that is tested against each of the cells in the
supplied range.
Formulas: Results:
A A
11 =COUNTIF( A1:A9, "Wednesday" ) 11 3
12 =COUNTIF( A1:A9, "<>Wednesday" ) 12 6
13 =COUNTIF( B1:B9, ">01/10/2008" ) 13 2
14 =COUNTIF( C1:C9, 0 ) 14 2
15 =COUNTIF( C1:C9, ">=3" ) 15 4
16 =COUNTIF( D1:D9, TRUE ) 16 3
COUNTIFS function
Function Description
The Excel Countifs function returns the number of rows within a table, that satisfy a set
of given criteria.
The function is new in Excel 2007, and so is not available in earlier versions of Excel.
The Countifs function can be used to find the number of rows in the data set that satisfy
conditions relating to the subject, score and gender.
A B C D
1 Name Gender Subject Score
2 Anne Female Maths 63%
3 Anne Female English 78%
4 Anne Female Science 39%
5 Carl Male Maths 55%
6 Carl Male English 71%
7 Carl Male Science 51%
8 Kath Female Maths 78%
9 Kath Female English 81%
10 Kath Female Science 49%
11 Tony Male Maths 35%
12 Tony Male English 69%
13 Tony Male Science 65%
Example 1
If we want to know how many female test scores were greater than 60%, we could use
the following formula:
Example 2
If we want to know how many science tests scores were less than 50%, we could use
the formula:
lookup_value - The value that you want to search for, in the first row of the
supplied data array.
row_index_num - The row number, within the supplied table_array, that you want
the corresponding value to be returned from.
Formulas: Results:
In the above example, the Hlookup function searches through the top row of
the table_array (the range A2-F2), to find a match for the lookup_value (the name "Ed").
When the name "Ed" is found, the function returns the corresponding value from the 5th
row of the table_array.
This is illustrated in the spreadsheet on the right. The function finds the name 'Ed' in the
top row of the table_array and then returns the value '61%' from the 5th row of
the table_array.
If we change the name in cell A10 of the spreadsheet from 'Ed' to 'Cara', the Hlookup
function would automatically recalculate the function to display the exam result for Cara.
Note that although the top row of the table_array is in ascending order in this example,
this is not essential, because the [range_lookup] argument is set to FALSE (requiring an
exact match).
Cell C6 shows the user's current BMI, which is 23.5, and cell C7 shows the Hlookup
function that is used to look up the body type that relates to this BMI.
The Hlookup function in the above spreadsheet returns the result "Normal Weight",
which is the correct body type for a BMI of 23.5.
Note that, in this example, the [range_lookup] argument is set to TRUE, to tell that
function that, if it cannot find an exact match to the supplied lookup_value, it should use
the closest match below this value. Therefore,
• For all BMIs up to and including 18.4 the function would return "Underweight";
• For all BMIs between 18.5 and 24.9, the function would return "Normal Weight";
VLOOKUP function
Function Description
The Excel VLOOKUP function 'looks up' a given value in the left-hand column of a data
array (or table), and returns the corresponding value from another column of the array.
table_array - The data array or table, containing the search values in the left
hand columns and the return values in another column.
col_index_num - The column number, within the supplied table_array, that you
want to return a value from.
Vlookup Examples
Example 1 - Vlookup Requiring an Exact Match
Columns A and B of the spreadsheet below list an inventory of grocery items and their
prices. In cell E2 of the spreadsheet, the Vlookup function is used to look up the price of
an item from the inventory.
A B C D E
Cost Current
1 Item Description ($) Item: Current Item Cost ($)
Tinned =VLOOKUP( D2, A:B, 2, - returns the value
2 Tomatoes $0.90 Cornflakes FALSE ) $3.50
3 Tinned Tuna $1.50
4 Cornflakes $3.50
Shortcake
5 Biscuits $1.00
6 Toothpaste $4.10
Tinned Baked
7 Beans $0.99
White Sliced
8 Bread $0.80
. .
. .
9 . .
The above Vlookup function returns the price for "Cornflakes", which is $3.50.
In this example:
• The lookup_value is the text string "Cornflakes", which is located in cell D2;
• The table_array is defined as columns A-B of the spreadsheet;
• The col_index_num is set to 2, to denote that the value returned should be taken from
column 2 of the table_array;
• The [range_lookup] argument is set to FALSE, to indicate that we only want a result to
be returned if an exact match to the lookup_value is found.
Note that in this example, as the [range_lookup] argument is set to FALSE (requiring an
exact match), it is not necessary to order the table_array by its first column.
Cell F2 shows the score of 52% that was achieved by the student "Anne" in an
examination. The Vlookup function in cell G2 looks up this score in column A of the
spreadsheet and returns the associated grade from column C.
Note that, in this example, if the exact score of 52% is not found in column A, we want,
instead, to use the nearest value below this score.
A B C D E F G
Lowe Uppe Grad Nam Scor
1r r e e e Grade
=VLOOKUP( F2, A2:C7, 3, - returns the value
2 0% 44% F Anne 52% TRUE ) "E"
3 45% 54% E
4 55% 64% D
5 65% 74% C
6 75% 84% B
100
7 85% %A
The above Vlookup function returns the grade for the score 52%, which is E.
In this example:
The lookup_value is the value 52%, which is located in cell F2;
The table_array is the range A2-C7 of the spreadsheet;
The col_index_num is set to 3, to denote that the returned value should be taken
from column 3 of the table_array;
The [range_lookup] argument is set to TRUE, to indicate that, if an exact match to
the lookup_value is not found, we want the closest value below the lookup_value to
be returned instead.
(Note that, in this case, the first column of the table_array (i.e. cells A2-A7) must be
in ascending order).