Save content
Have you found this content useful? Use the button above to save it to your profile.
AIA

Extend SUM, MIN, and MAX formulae

by
11th Jul 2011
Save content
Have you found this content useful? Use the button above to save it to your profile.

AccountingWEB.com contributor David H. Ringstrom CPA recently published a collection of useful tips on how popular formulae can be extended by using multiple criteria. Here are the highlights.
 
By now most accountants probably know their way around Excel’s SUM, MIN, and MAX functions in Excel. Typically, each of these functions is used to derive a result from a range of cells, for example:

  •  =SUM(C2:C6) would add up all values in cells C2 through C6
  • =MIN(C2:C6) would return the smallest value within cells C2 through C6
  • =MAX(C2:C6) would return the largest value within cells C2 through C6

 
Here we see a typical use of the three functions to analyse some payroll data:

Excel SUM, MIN & MAX functions

But there are times when these kinds of calcuations are not enough. In some instances you may want to add some extra criteria. It’s simple to do, but you need to add a special keystroke after you type the formula.

You’re probably used to pressing Enter once you’ve typed a formula in a cell. To add more criteria to a formula, you’ll need to press Ctrl-Shift-Enter after you type the formula. If you accidentally push the Enter key and Excel accepts a shorter version of the formula you want, press F2 to edit it, and then press Ctrl-Shift-Enter.

Now, let’s say that we want to get the sum of just the jobs in the Operations department with a job code of 100. To do so, put the word Operations in cell F2, and the number 100 in cell E3. Next, enter the following formula in cell F3, and then press Ctrl-Shift-Enter:
=SUM(IF(($A$2:$A$6=F$2)*($B$2:$B$6=$E3),$C$2:$C$6))
 
You’ll notice that there’s an IF statement within the SUM. This allows us to specify multiple criteria, which we separate with an asterisk. Thus, ($A$2:$A$6=$F$2) identifies the cells in column A that contain the word Operations. The second criteria ($B$2:$B$6=$E3) identifies the cells in column B that contain the value 100. When both of these criteria are met, Excel creates an array of the corresponding values from cells $C$2:$C$6. Since the IF statement is contained within a SUM function, Excel adds up the values that meet both criteria. Although I only specified two criteria here, you can feel free to enter more criteria as needed.
 
You’ll notice that when you press Ctrl-Shift-Enter the formula bar displays curly brackets around the formula:
={SUM(IF(($A$2:$A$6=F$2)*($B$2:$B$6=$E3),$C$2:$C$6))}
 
The curly brackets indicate an array formula – these are special types of formulas in Excel that can carry out sophisticated techniques such as summing a range based on multiple criteria. Don’t type the curly brackets yourself – Excel adds them automatically when you press Ctrl-Shift-Enter.
 
To better understand how array formulas work, let’s step through the components. If you clicked on cell F3, and selected the first criteria within the formula, this is what you would see:

Selecting criteria within a compound SUM formula

Pressing F9 would then show the corresponding values for this portion of the formula:

Press F9 in Excel to display the values for selected portion of the forumla
 
Notice that ($A$2:$A$6=G$2) changes to {TRUE;TRUE;FALSE;TRUE;TRUE}. The TRUE values indicate cells where the word Operations appears, FALSE appears when something else is in the cell.
 
Next, select this portion of the formula and press F9: ($B$2:$B$6=$E3)
 
Your formula should now look like this:
=SUM(IF({TRUE;TRUE;FALSE;TRUE;TRUE}*{TRUE;TRUE;TRUE;FALSE;FALSE},$C$2:$C$6))
 
You can see that both sets of criteria return TRUE for the first two values. The last 3 values return varying combinations of TRUE/FALSE. Excel uses the TRUE values to identify which cells to add up in the range C2:C6.
 
Finally, select the entire IF statement in the formula bar and press F9 to see this result:
=SUM({22;72;FALSE;FALSE;FALSE})
 
The word FALSE and zero are interchangeable in Excel formulas, which is why SUM can add up all of the values and only return a value for the cells where both criteria are met. In essence, Excel creates an array that stores the values that it sums, rather than referring to a set range of cells. This allows array formulas to perform calculations that aren’t possible with typical worksheet formulas.
 
This F9 technique is a helpful formula auditing tool, but be sure to press the Escape key to restore your formula. If you press Enter or Ctrl-Shift-Enter, you’ll replace your cell references with static values. If you forget to press Escape, press Ctrl-Z immediately to restore the original formula.
 
Also, there are other alternatives for summing ranges based on multiple criteria. Excel 2007 and 2010 users can use the new SUMIFS function, while the SUMPRODUCT function works in any version of Excel. Array formulas such as those above also work in any version of Excel, and provide yet another way to analyse data in Excel.
 
Now that we understand how the SUM function works with multiple criteria, we can apply the exact same technique with the MIN and MAX functions. Cell G3 in Figure 1 contains this formula:
 
=MIN(IF(($A$2:$A$6=G$2)*($B$2:$B$6=$E3),$C$2:$C$6))
 
Cell H3 in Figure 1 contains this formula:
=MIN(IF(($A$2:$A$6=H$2)*($B$2:$B$6=$E3),$C$2:$C$6))
 
Don’t forget to press Ctrl-Shift-Enter after you type these formulas.

About the author
"Either you work Excel, or it works you!" says David Ringstrom CPA, the head of Atlanta-based software and database consultancy Accounting Advisors. He presents Excel training webcasts for AccountingWEB partner CPE Link and contributes articles on Excel to Microsoft Professional Accountant's Network newsletter. He can be reached by email at david[AT]acctadv.com.
Tags:

Replies (1)

Please login or register to join the discussion.

By dialm4accounts
14th Jul 2011 18:34

Alternative to pivot tables

Great article.

I'm thinking the same result could be achieved by using a pivot table?

M

--

Emily Coltman MA (Cantab) ACA

Chief Accountant, FreeAgent Central Ltd Quartermile Two, 2 Lister Square, Edinburgh, EH3 9GL Registered in Scotland SC316774

-------------------------------------------------------------------

Thanks (0)