Most Excel users are familiar with the SUM, MIN, and MAX functions in Excel. Used in their traditional fashion, you provide a range of cells to the function to derive a result:

- =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

As shown in Figure 1, these formulas return 225,000, 29,000, and 70,000, respectively.

** Figure 1:** Sample payroll information that we wish to analyze

However, in certain cases you may wish to use this functions based on multiple criteria. It’s a simple process to do so, but one that requires a special keystroke after you type the formula. Typically you simply press Enter once you type a formula in a cell. However, in the case of the multiple criteria formulas I’m about to share, you’ll press Ctrl-Shift-Enter after you type the formula. Excel will accept the formula if you slip and just press the Enter key, but the formula may not return the desired result. In such cases, simply press F2 to edit the formula, 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.

Click on cell F3, and then select the first criteria within the formula, as shown in Figure 2.

** Figure 2: **Select the first criteria within the formula

** Figure 3:** Press F9 to show the corresponding values for a portion of an Excel formula

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.

Keep in mind that the F9 trick I just shared 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 analyze 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.

### Related content

David H. Ringstrom, CPA, is an author and nationally recognized instructor who teaches scores of webinars each year. His Excel courses are based on over 25 years of consulting and teaching experience. His mantra is “Either you work Excel, or it works you.” David offers spreadsheet and database consulting services nationwide.

## Replies (9)

## Please login or register to join the discussion.

in your array formulas, what if $E3 is a value that either represents a project number or wildcard. Can $E3 represent a wildcard that will return everything in your array? This might be useful if $B3 were a pivot report and if ("All") were selected, a wildcard would be returned in $E3 so every project could be counted. If a specific project number were selected, $E3 would return that project number and the sum formula will only capture the array matching that criteria. Any feedback is much appreciated.

Cany any one help me to use the similar formula in excel to find out

the sum the Row 3 IF row 1 is equal to "SecSch" AND row 2 is equal to Current

Say in excel Row 1 (contains a list of "Sec", "Pry", "RCs"), Row 2 (contains "Current" and "Capital") Row 3 (123 (budget)

Can you describe your problem in details so I can help?

Educa, If you're using Excel 2007 or later, the SUMIFS function allows you to sum values based upon multiple criteria. Based on your description, the formula might look like this:

=SUMIFS(3:3,1:1,"SecSch",2:2,"Capital")

If you're using Excel 2003 or earlier, use SUMPRODUCT instead:

=SUMPRODUCT((A1:Z1="SecSch")*(A2:Z2="Capital")*A3:Z3)

David

Very nice!! try visiting my post I explain in there how to get max value with condition:

http://runakay.blogspot.com/20...

Ronald,

Thank you for sharing your post, which is a great companion to this article. I've added your blog to my reading list of Excel resources.

David

rafshan

I got an error when using this formula.

Looking to find a formula that would take out 2 minimums in an excel row. The formula I was using just took out the lowest value: =SUM(B9:G9)-MIN(B9:G9). I am now looking to take out the 2 lowest values and looking for help to do so.