Excel SumIf CountIf and AverageIf formulas

Excel SumIf CountIf and AverageIf formulas

Using Sum(), Count() and Average() formulas in Excel might be enough for many situations, but sometimes you might have a more complex question you’re trying to answer.  For example, if you had the following data, and you wanted to know how much each customer bought, how many times they bought, and what was their average purchase, you will need a new set of formulas.  Don’t worry, though, you’ll see they are just as easy to use. The Excel SumIf(), CountIf() and AverageIf() formulas will give you the sum, count, and average of a value where a certain condition is matched.

To follow along, go to the following link to download the Efficient Analyst SumIf CountIf AverageIf Exercise Workbook:

Efficient Analyst Excel SumIf CountIf AverageIf

First, lets look at our sales data.  You might recognize this from a previous exercise.

Efficient Analyst SumIf 1

What you are looking for is a simple table as follows, so you can start learning more who your best customers are, and some of their buying habits.

Efficient Analyst SumIf 12

Let’s see which functions will give us the right information for each column:

Efficient Analyst SumIf 2

Using the Excel SumIf Formula

If you start writing =SumIf( in Excel, a tooltip will appear which gives you a reminder of how to use this formula.

Efficient Analyst SumIf 3

The first part you will need to fill out is the range.  In this case, the range will can be thought of as “Where do you want to look for this customer name?”, the answer being column C, which in Excel you can either click the column C header to select it, or write C:C. Let’s click the column header to select it:

Efficient Analyst SumIf 4

Also notice how the formula updated.
Efficient Analyst SumIf 5

The second section we have to fill is the criteria. The criteria is what you are trying to match, which in this case is Customer 1, which is found in cell I2, so we will select I2.

Efficient Analyst SumIf 6

Last but not least, we need to tell Excel what we need to sum, the sum range, which in this case would be the amounts found in column D.

Efficient Analyst SumIf 7

Congratulations, you know know how to use SumIf!. If you close the parenthesis ) of the formula and press enter, you will see how much Customer1 has purchased:

Efficient Analyst SumIf 13

Dragging Down a Formula to Copy it Over a Range

One of my favourite features of Excel is the ability to drag a formula down to copy it quickly over a range. Select the cell containing your SumIf formula, and then click and hold your left mouse button on the the little dot in the bottom right of that cell.

Efficient Analyst SumIf 8

While keeping your left mouse button pressed down, move your mouse cursor down over the area you would like to copy this formula to.

Efficient Analyst SumIf 9

Release the left mouse button, and you will see the formula copied itself over making adjustments as needed so the formula in cell J3 is matching the content in cell I3, etc.

Efficient Analyst SumIf 10

Using the Excel CountIf Formula

To find out how many times each customer placed an order, we will use the CountIf formula, which counts how many times some text appears in your selection. This formula is a little simpler than the other two, having only two sections: a range, and a criteria.

The first step consists in writing =countif( to see the Excel tooltip.

Efficient Analyst SumIf 11

The range comes first, which is where you want to look for a match, which in this case would be column C. You can either select column C, or write C:C in the formula bar.

Efficient Analyst CountIf 3

Next up is the criteria which is what we are trying to match, which in this case would be the content of cell I2.

Efficient Analyst CountIf 1

Closing the parenthesis ), pressing enter, and then using the dragging technique from before, we get the number of purchases per customer.

Efficient Analyst CountIf 2

Using the AverageIf Excel Formula

To obtain the average sales amount per order, we have two options. Since we already calculated the sum of the amounts and the count of orders, we could simply go in cell L2 and type =J2/K2. But since this is a tutorial, let’s use this exercise as an excuse to learn AverageIf, that way you don’t have to use SumIf and CountIf if all you’re looking for is the average.

As usual, type =averageif( in a cell will give you the tooltip on how to use this tool. If you look at the 3 arguments of this formula: range, criteria, and average range, you’ll notice this follows the same structure as the SumIf() formula we have just seen.

Using a range of column C, a criteria of cell I2, and an average range of column D, we get the following formula:

Efficient Analyst AverageIf 1

Using the same drag-down technique as before, we get the average sales per customer.

Efficient Analyst AverageIf 3

Creating an Excel Drop-down list using Data Validation List

Creating an Excel Drop-down list using Data Validation List

Adding an Excel Drop-down list is a great way to make data entry faster, more efficient, and also more accurate.  There are a few ways they can be done, and in this article we show how to do them using the Data Validation lists.

To follow along, go to the following link to download the Efficient Analyst Data Validation List Drop-Down Exercise Workbook:
Efficient Analyst Data Validation List Drop-down Exercise Workbook

Procedure steps

To create an Excel drop-down list, select the cell where you would like the drop-down to appear, and open the Data ribbon.

In the Data ribbon, select Data Validation -> Data Validation…

Efficient Analyst Excel Drop-down list Data Validation List Dropbox Data Validation -> Data Validation

In the Data Validation dialog box, select List.

Efficient Analyst Excel Drop-down list Data Validation List Dropbox Data Validation List

Click the Select Source button.

Efficient Analyst Excel Drop-down list Data Validation List Dropbox select source

Type or select the range you would like to include as part of your Excel drop-down list.

Efficient Analyst Excel Drop-down list Data Validation List Dropbox select source range

Congratulations, your Excel drop-down list is now ready to be used!

Efficient Analyst Excel Drop-down list Data Validation List Dropbox

Using the Excel VLOOKUP function

Using the Excel VLOOKUP function

Using the Excel VLOOKUP function makes it easy to link two excel tables together, and can be a great time saver.

To follow along, go to the following link to download the Efficient Analyst VLOOKUP Exercise Workbook: Efficient Analyst VLOOKUP Exercise Workbook

Procedure steps

As an example of how the Excel Vlookup function works, let’s take a simple excel workbook with the following two tabs: Orders and Customers.

Using Excel VLOOKUP function - Orders and Customers tabs

The Orders tab contains an order number, date, customer name, and amount.

Using Excel VLOOKUP function - Orders tab

We want to add the Country, City, and Phone number of each customer, which thankfully we have in the Customers tab.

Using Excel VLOOKUP function - Customers tab

By using the Excel VLOOKUP function, we can quickly and efficiently fill in the Country, City, and Phone in the Orders tab.

Let’s go back to the Orders tab, and start typing the =vlookup( formula to see the tooltip provided by Microsoft:

Using Excel VLOOKUP function - Vlookup arguments

If you’ve never used the Excel vlookup function before, this provides absolutely no help.  But lets break it down in an easier way:

Argument Description Example Example Code
lookup_value The value which is in common between both tables In this case, Customer Name, more specifically, if we are trying to find the Country for the customer on line two (i.e. we are trying to fill cell E2), we would select cell C2 as the customer name. C2
tabble_array Where the information you are looking for is located. The first column should contain the common element, and the range should be large enough to include In this case, it would be the Customers tab, columns A through D. Customers!A:D
col_index_num Based on the range you put in table_array, the col_index_num is the number of the column which contains the result you are looking for. For example, if you selected A:D as your range, and the common element is in column A, and the result is in column B, you would put 2 as your column number. Putting 3 would give you the result from column C, and putting 4 would give you the result from column D. However, if you select L:P as your range, then column 1 is L, column M is 2, column N is 3, etc. Because the country code is located in column B of the Customers tab, we will select 2 2
[range_lookup] Last and definitely not least, the range_lookup gives you a true or false option. False will only return an exact match, while True will try to look for a result which looks similar to what you are looking for. 99%+ of the time I find False to be the best option to use. For example, if you had an order for Customer8, because there is no Customer8 in the customers tab, using false would return #N/A meaning Excel could not find a match. This would let you know that you have to add Customer8 to the Customers tab. If you select true, that same Customer8 would return United States, because Customer8 looks similar to Customer7, which is in the US. false

We end up with the following formula: =VLOOKUP(C2,Customers!A:D,2,FALSE), where C2 is the Customer we are trying to match up, Customers!A:D contains the customer information we want to look into, 2 is the 2nd column from that range, and False because we only want exact matches.

Using the same method, we can create the formulas for F2 and G2 by changing the 2 to a 3 or a 4.  (I changed my view settings in Excel to show the formulas instead of the values, so you should see Canada, Ottawa, and (555) 555-0001 instead of the formulas)

Using Excel VLOOKUP function - first row formulas

You can then select a formula and drag the little dot in the corner to fill in the other formulas very quickly:

Using Excel VLOOKUP function - Drag down formulas

Which would give us the following formulas (again in formula view):

Using Excel VLOOKUP function - All formulas

Here is what you should see on your screen at the end.  By using the formula dragging feature, you can very quickly perform vlookups for thousands of records!

Using Excel VLOOKUP function - All results

Additional Tips

  • Using full columns as your range, for example A:D instead of A2:D7, makes it easier to add/remove items from your table without having to change the 2 and 7 all the time.
  • If you do use a range such as A2:D7, remember that if you drag your formula down, you will get A3:D8, A4:D9, etc, and if you drag your formula right, you will get B2:E7, C2:F7, etc.  The easiest way to prevent this is to use $ signs to make sure the range doesn’t change, such as $A$2:$D$7.