Summing up ways to add and count Excel data Adding and counting data is the bedrock of data analysis, whether you are tallying an exact head count of an organization, subtotaling sales in the Northwest region, or doing a running total of weekly receipts. Microsoft Office Excel provides multiple techniques that you can use to add and count data. This article provides the basics of some of the more commonly used methods and provides links to articles that go into detail on those methods. To help you make the right choice, here's a comprehensive summary of methods and links to more information. Each section has supporting information to help you quickly decide on which technique to use and links to in-depth articles. Adding and subtracting numbers The following sections summarize the specific tasks for adding numbers, the best Excel feature for each task, and provide links to one or more Help topics for specific examples and information. Simple addition and subtraction You can add and subtract numbers by using a simple formula, a button, or by using a worksheet function. Add values in a cell by using a simple formula If you just need a quick result, you can use Excel as a mini calculator. Do this by using the plus sign (+) arithmetic operator. For example, if you type the formula =5+10 in a cell, Excel displays 15 as the result. Subtract values in a cell by using a simple formula Do this by using the minus sign (-) arithmetic operator. For example, the formula =12-9 displays a result of 3. Add values in a column or row by using a button You can use AutoSum to quickly sum a range of numbers in a column or row. Click an empty cell below a column of numbers or to the right of a row of numbers, and then click AutoSum. Excel selects what it determines to be the most likely range of data. Click AutoSum again to accept the range that Excel selects, or select your own range and then click AutoSum. Add values in a range by using a function The SUM function is useful when you want to add values from different ranges or combine number values with ranges of numbers. Use the SUM function to add all the arguments that you specify within the opening and closing parentheses. Each argument can be a range, a cell reference, or a numeric value. To enter a simple formula, type =SUM in a cell, followed by an opening parenthesis. Next, type one or more numbers, cell references, or cell ranges, separated by commas. Then, type a closing parenthesis and press ENTER to display the result. You can also use your mouse to select cells that contain data that you want to sum. A 1 Attendance 2 4823 3 12335 For example, using the data in the preceding table, all of the following formulas use the SUM function to return the same value (17158): =SUM(4823,12335) =SUM(A2,A3) =SUM(A2:A3) =SUM(A2,12335) The following figure shows the formula that uses the SUM function to add the value of cell A2 and 12335. Below the formula, a ScreenTip provides guidance for using the SUM function. NOTES There is no SUBTRACT function in Excel. To subtract values by using a function, use the negative values with the SUM function. For example, the formula =SUM(30,A3,-15,-B6) adds 30 and the value in cell A3, subtracts 15, and also subtracts the value in cell B6. You can include up to 255 numeric values or cell or range references, in any combination, as arguments in the SUM function. Summing data by grouping and pivoting You can use an outline or a PivotTable report to group and summarize your data. Add values in a column by using an outline If your data is in a list and you can logically group it by column values, you can group and summarize data by creating an outline. Creating an outline can summarize data by inserting subtotals and grand totals. Suppose you have the following sales figures, arranged by region and month. A B C 1 Region Month Sales 2 East Jan $18,000 3 East Feb $23,000 4 East Mar $19,000 5 West Jan $17,000 6 West Feb $27,000 7 West Mar $21,000 The following illustration shows an outline with subtotals, grouped by region, and a grand total. Use the Subtotal command (Data tab, Outline group) to create an outline, subtotals, and a grand total. The original data included three rows of data for the East region and three rows of data for the West region (rows 2 through 7). Note that the subtotal operation inserted the East Total in row 5 between the last row of East data and the first row of West data. If you click cell A4 and then click the Subtotal command, Excel creates an outline and inserts rows for East Total, West Total, and Grand Total, and populates the cells in the Sales column with those totals. Add values in a list or Excel table column by using a function As a more flexible alternative to the Subtotal command, you can use the SUBTOTAL function to calculate subtotals and grand totals on lists or Excel tables that contain hidden rows or columns. In the SUBTOTAL function, you specify an argument that either includes or does not include hidden values. NOTE The SUBTOTAL function can control whether or not hidden rows are included in the results and always ignores rows that have been filtered. For example, suppose that you want to calculate subtotals and a grand total for data in cells C2 through C7, but you want to ignore the hidden data in row 3 and row 6. The function you use looks like the following: =SUBTOTAL(109,C2:C7) The first argument (109) specifies that you want to add the values in the range and ignore hidden values. To include the hidden values, you instead use 9 as the first argument. Sum your data and look at it from different perspectives When a worksheet contains hundreds or even thousands of rows of similar data, it can be difficult to draw meaning from those numbers. You can build a PivotTable report in Excel from that data that shows subtotals, grand totals, and that can summarize data based on categories that you specify. You can quickly create a PivotTable by selecting a cell in a range of data or Excel table and then, on the Insert tab, in the Tables group, clicking PivotTable. To show the power of a PivotTable, note that in the following example, the sales data contains many rows (there are actually 40 rows of data, but the graphic shows only a portion), it isn't summarized, and it has no subtotals or grand total. A PivotTable report based on the same data shows subtotals, grand totals, and provides a concise summary at a glance. Creating and working with PivotTables may require some initial preparation of your data and a familiarity with some concepts. Adding with one or more criteria Using worksheet functions, you can apply criteria so that you add only the data that meet conditions that you specify. Add values in a range based on a single condition by using a single function or a combination of functions Use either the SUMIF function or nest the SUM function inside the IF function. You can add numbers based on a single criterion by using the SUMIF function or by using a combination of the SUM and the IF functions. For example, the formula =SUMIF(A2:A6,">20") adds only the numbers in the range A2 through A6 that are greater than 20. NOTE The following information is a little bit technical, but definitely worth learning. If the SUMIF function didn't exist, you could still come up with the same answer by combining the IF and the SUM functions. Combining functions in this way is also known as "nesting," because one function is used in another function. To create a formula that mimics the SUMIF function, you enter a formula that treats the range A2 through A6 as an array, which means that the range is considered as a single entity containing five cells. Your formula looks like this: {=SUM(IF(A2:A6>20,A2:A6))}. The "curly" braces that surround the formula indicate that this is an array formula. An array formula requires some special treatment: Instead of typing the braces yourself, you must instead press CTRL+SHIFT+ENTER — Excel then surrounds the formula =SUM(IF(A2:A6>20,A2:A6)) with the braces. If you type the braces yourself, you won't create an array formula. Add values in a column based on single or multiple criteria by using a function Use the DSUM function to add the numbers in a field (column) of records in a list or database that match conditions that you specify. You can also use the DSUM function when you have a column list and you find it easier to define your criteria in a separate range of cells, rather than use a nested function. Add values in a range based on multiple criteria by using a wizard You can use the Conditional Sum Wizard (Conditional Sum command, in the Solutions group on the Formulas tab) to add values that are based on multiple criteria. To use the Conditional Sum Wizard, select your range of data and click the Conditional Sum command (Solutions group on the Formulas tab). Follow steps 1 through 4 to complete the wizard. The following illustration shows step 2 of the wizard, in which there is one condition: The values to be summed must be greater than 100. Add values in a range based on multiple criteria by using a single function or a combination of functions Use the SUMIFS function. Provide the range that you want to sum, a range that contains criteria, and the criteria that are applied to the criteria range. As an alternative, you can nest the SUM and IF functions. Adding squared and array values You can use worksheet functions to add values in two or more columns that correspond to each other. This type of operation can be as simple as determining a weighted average (see the sample that follows), or it can be a complex statistical or engineering calculation. Add the product of corresponding values in one or more arrays Use the SUMPRODUCT function. For example, you can calculate a student's grade point average by using the SUMPRODUCT function and dividing that result by the number of credits, as shown in the following figure. The formula =SUMPRODUCT(A2:A6,B2:B6)/SUM(B2:B6) multiplies the grade achieved for each class by its number of credits, sums those products (61.3), divides that sum by the total credits (18), and determines the grade point average (3.41). This type of calculation is also known as a weighted average. You can also use the SUMPRODUCT function in more advanced mathematical operations by multiplying several arrays. The SUMPRODUCT function is easy to use with arrays that have the same dimensions, but you can also use the SUM function in an array formula if you need more flexibility. Add the square of each value in a range Use the SUMSQ function to return the sum of the squares of a list of numbers or values in a range. For example, SUMSQ(2,3) returns 13. NOTE This type of calculation is often used with statistics and complex math. Add the sum of the square of corresponding values in two arrays Use the SUMX2PY2 function to add the sum of the squares of corresponding values in two arrays. This is used in many statistical calculations. NOTE This type of calculation is often used with statistics and complex math. Add the difference of the square of corresponding values in two arrays Use the SUMX2MY2 function to return the sum of the difference of squares of corresponding values in two arrays. NOTE This type of calculation is often used with statistics and complex math. Add the square of the difference of corresponding values in two arrays Use the SUMXMY2 function to return the sum of squares of differences of corresponding values in two arrays. NOTE This type of calculation is often used with statistics and complex math Special cases (running total, unique values) You can use worksheet functions to create totals that update as you add more data to a range or table, or to add only the unique values that are found in a range or table. Create a running total by using a function Use the SUM function. For example, create column headings in a worksheet named Deposits, Withdrawals, and Balance. 1. In the first cell under the Balance column, enter your beginning balance. 2. In the cell directly below, enter a formula that adds the value from the Deposits column in the same row and subtracts the value from the Withdrawals column (=SUM(C2,A3,-B3). 3. Drag this formula down to any new rows that you add (in this case, drag it to row 4). This is shown in the following example. The example may be easier to understand if you copy it to a blank worksheet. 1 2 A B C Deposits Withdrawals Balance 500 3 4 1000 625 =SUM(C2,A3,-B3) 1000 740 =SUM(C3,A4,-B4) You can use a running balance as you would use a check register to watch values of items in cells increase or decrease as you enter new items and values over time. Add unique values in a range by using a mega-formula In a column, enter a list of values that contains duplicates, and then use a combination of the SUM, IF, and FREQUENCY functions to add only the unique values that are found in that range. Including values from other worksheets or workbooks in a formula You can add or subtract cells or ranges of data from other worksheets or workbooks in a formula by including a reference to them. To refer to a cell or range in another worksheet or workbook, use instructions in the following table. To refer to: Enter this Examples A cell or range in another worksheet in the same workbook The name of the worksheet followed by an exclamation point, followed by the cell reference or range name. Sheet2!B2:B4 Sheet3!SalesFigures A cell or range in another workbook that is currently open The file name of the workbook in brackets ([]) and the name of the worksheet followed by an exclamation point, followed by the cell reference or range name. [MyWorkbook.xlsx]Sheet1!A7 A cell or range in another workbook that is not open The full path and file name of the workbook in brackets ([]) and the name of the worksheet followed by an exclamation point, followed by the cell reference or range name. If the full path contains any space characters, surround the start of the path and the end of the worksheet name with single quotation marks (see the example). ['C:\My Documents\[MyWorkbook.xlsx]Sheet1'!A2:A5 Adding and subtracting date and time values You can use date and time functions and even simple addition or subtraction to calculate elapsed time, estimate completion dates for projects, and more. The following table shows some formulas that calculate elapsed times and days. Note that if you subtract a date or time that results in a negative value, Excel displays ### characters in the cell that contains the formula. A 1 B Start time End time Elapsed time formula Description (result) 11:55:24 AM 2:48:13 PM =B2-A2 Displays elapsed time in hours, minutes, and seconds. In this case, Excel displays the result (2:52:49 AM) in an "AM" format because the difference is less than 12 hours. If the difference were 12 hours or more, Excel would display a "PM" format. Start date End date Elapsed days formula Description (result) 5/28/2008 6/03/2008 =B5-A5 Displays elapsed days as a number (6). 2 3 C 4 5 Working with date and time values can produce unexpected results, so proceed carefully. Displaying calculations and counts on the status bar When one or more cells are selected, information about the data in those cells is displayed on the Excel status bar. For example, if four cells on your worksheet are selected, and they contain the values 2, 3, a text string (such as "cloud"), and 4, all of the following values can be displayed on the status bar at the same time: Average, Count, Numerical Count, Min, Max, and Sum. Right-click the status bar to show or hide any or all of these values. These values are shown in the illustration that follows. NOTE In earlier versions of Excel, these same values can be displayed on the status bar, but only one value at a time. Counting number and text values The following sections summarize the specific tasks for counting number and text values, the best Excel feature for each task, and provide links to one or more Help topics for specific examples and information. Simple counting You can use the AutoSum command or a function to count the number of values in a range or table. In addition, Excel can also display, on the status bar, the count of the number of selected cells on a worksheet. Count cells in a column or row by using a built-in command Use the Count Numbers AutoSum command. Select a cell below or to the right of the numbers that you want to count, and click the arrow next to the AutoSum command. Then, click Count Numbers. You can use AutoSum for more than just summing; you can use it to count the numbers in a range and also to find the minimum and maximum values. Count cells in a range by using a function Use the COUNT function to count the number of numeric values in a range. For example, the range A2:A5, as shown in the following table, contains three numbers and one text value. You use the COUNT function like this: =COUNT(A2:A5). The result is 3; the number of numeric values found in the range. A 1 Sample value 2 5 3 12 4 hello 5 3 The COUNT function is useful when you want to count values from different ranges or combine literal values with ranges of values. For more information, see the section "Count cells that contain numbers that are not in a contiguous row or column" in the article COUNT function. Count cells in a column by using an outline Use the Subtotal command (Data tab, Outline group) to group and summarize a column of data. If your data is in a list and you can logically group it by column values, you can create an outline to group and summarize it. Count cells in a column or row by using a PivotTable Create a PivotTable report that summarizes your data and helps you perform analysis by letting you choose the categories on which you want to view your data. You can quickly create a PivotTable by selecting a cell in a range of data or Excel table and then, on the Insert tab, in the Tables group, clicking PivotTable. Creating and working with PivotTables may require some initial preparation of your data and a familiarity with some concepts. Count cells in a list or Excel table column by using a function Use the SUBTOTAL function to count the number of values in an Excel table or range of cells. The SUBTOTAL function can control whether or not hidden rows are included in the results and always ignores rows that have been filtered. Counting with one or more criteria You can count the number of cells in a range that meet criteria that you specify by using a number of worksheet functions. Count cells in a range based on a single criterion Use the COUNTIF function to count the number of cells that meet one condition. Count cells in a column based on single or multiple criteria To match conditions that you specify, use the DCOUNT database function. Use the DCOUNT function when you have a column list and you find it easier to define your criteria in a separate range of cells, rather than use a nested function. Count cells in a range based on multiple criteria by using a single function or a combination of functions Use the COUNTIFS function or a combination of the COUNT and IF functions. Counting with blank values You can count cells that either contain data or are blank by using worksheet functions. Count nonblank cells in a range by using a function Use the COUNTA function to count only cells in a range that contain values. When you count cells, sometimes you want to ignore any blank cells because only cells with values are meaningful to you. For example, you want to count all salespeople who made at least one sale in a region. Count nonblank cells in a list by using a function Use the DCOUNTA function to count nonblank cells in a column of records in a list or database that match conditions that you specify. Count blank cells in a contiguous range by using a function Use the COUNTBLANK function to return the number of blank cells in a contiguous range (cells are contiguous if they are all connected in an unbroken sequence). If a cell contains a formula that returns empty text (""), that cell is counted. NOTE When counting cells, sometimes you want to include blank cells because they are meaningful to you. For example, you want to count all salespeople in a region, whether or not they made a sale. Count blank cells in a discontiguous range by using a combination of functions Use a combination of the SUM function and the IF function. In general, you do this by using the IF function in an array formula to determine whether each referenced cell contains a value, and then summing the number of FALSE values returned by the formula. Counting unique occurrences You can count unique values in a range by using a PivotTable report, by using the COUNTIF function, by using a combination of functions, or by using the Advanced Filter dialog box. Count unique values in a range by using a PivotTable report You can use a PivotTable report to display totals and count the occurrences of unique values. Count unique values in a range based on a single criterion by using a function Use the COUNTIF function to count the number of times a value occurs in a range. Count unique values in a range based on multiple criteria by using a combination of functions in an array formula Use the SUM function with the IF function. In general, you do this by using the IF function in an array formula to determine whether criteria that is composed of multiple conditions is met, and then summing the number of TRUE values returned by the formula. Count the number of unique values in a list column by using Advanced Filter Use the Advanced Filter dialog box to extract the unique values from a column of data and paste them to a new location. Then you can use the ROWS function to count the number of items in the new range. The simplest way to do this is by using the Advanced command (Data tab, Sort & Filter group). The following figure shows how you use the Advanced Filter to copy only the unique records to a new location on the worksheet. In the following figure, column C contains the five unique values from the range in column A. Count the number of unique values in a range with one or more criteria by using a mega-formula Use various combinations of the IF, SUM, FREQUENCY, MATCH, and LEN functions. Special cases (count all cells, count words) You can count the number of cells or the number of words in a range by using various combinations of worksheet functions. Count the total number of cells in a range by using functions Suppose you want to determine the size of a large worksheet to decide whether to use manual or automatic calculation in your workbook. To count all the cells in a range, use a formula that multiplies the return values from the ROWS and COLUMNS functions. 1 A B C Region Month Sales 2 East Jan $18,000 3 East Feb $23,000 4 East Mar $19,000 5 Formula Description (result) 6 =ROWS(A2:C4) * COLUMNS(A2:C4) The total number of cells in the range (9) Count words in a range by using a mega-formula Use a combination of the SUMIF, LEN, TRIM, and SUBSTITUTE functions in an array formula. In brief, to find the total number of words in the specified range, the array formula counts the words in each cell of that range, and the SUM function then sums the number of words in each cell to find the total. Displaying calculations and counts on the status bar When one or more cells are selected, information about the data in those cells is displayed on the Excel status bar. For example, if four cells on your worksheet are selected, and they contain the values 2, 3, a text string (such as "cloud"), and 4, all of the following values can be displayed on the status bar at the same time: Average, Count, Numerical Count, Min, Max, and Sum. Right-click the status bar to show or hide any or all of these values. These values are shown in the illustration that follows. NOTE time. In earlier versions of Excel, these same values can be displayed on the status bar, but only one value at a