SUMIFS
The SUMIFS function returns the sum of the cells in a collection where the test values meet the given conditions.
SUMIFS(sum-values, test-values, condition, test-values…, condition…)
sum-values: A collection containing the values to be summed. sum-values can contain number values, date/time values, or duration values.
test-values: A collection containing values to be tested. test-values can contain any value.
condition: An expression that compares or tests values and results in the boolean value TRUE or FALSE. condition can include comparison operators, constants, the ampersand concatenation operator, references, and wildcards. You can use wildcards to match any single character or multiple characters in the expression. You can use a ? (question mark) to represent one character, an * (asterisk) to represent multiple characters, and a ~ (tilde) to specify that the following character should be matched rather than used as a wildcard. condition can also contain a REGEX function instead of wildcards.
test-values…: Optionally include one or more additional collections containing values to be tested. Each test-values collection must be followed immediately by a condition expression. This pattern of test-values, condition can be repeated as many times as needed.
condition…: If an optional collection of test-values is included, condition… is an additional expression that results in a boolean value TRUE or FALSE. There must be one condition following each test-values collection; therefore, this function always has an odd number of arguments.
Notes
For each of the test and condition value pairs, the corresponding (same position within the collection) cell or value is compared to the condition. If all of the conditions are met, the corresponding cell or value in sum-values is included in the sum.
All collections must be of the same size.
Examples |
---|
Given the following table: |
A | B | C | |
---|---|---|---|
1 | Tons | Rating | Date |
2 | 6 | 1 | 12/10/12 |
3 | 15 | 2 | 12/10/12 |
4 | 5 | 1 | 12/13/12 |
5 | 7 | 2 | 12/13/12 |
6 | 8 | 2 | 12/14/12 |
7 | 6 | 1 | 12/15/12 |
8 | 7 | 2 | 12/15/12 |
9 | 4 | 2 | 12/16/12 |
10 | 7 | 1 | 12/16/12 |
11 | 8 | 2 | 12/16/12 |
12 | 5 | 1 | 12/17/12 |
13 | 11 | 2 | 12/20/12 |
=SUMIFS(A2:A13, B2:B13, "=1", C2:C13, ">=12/13/2012", C2:C13, "<=12/17/2012") returns 23, the number of tons of the commodity delivered during the week of December 17 that were rated 1. The collection A2:A13 contains the number of tons, which are the values to be summed (sum-values). The collection B2:B13 (test-values) contains the first value to be tested for a rating of 1 (condition). The collection C2:C13 (test-values…) contains the second value to be tested to find a match for a starting date (condition…). This same range also contains the third value to be tested, an ending date. Rows 4 (5 tons), 7 (6 tons), 10 (7 tons), and 12 (5 tons) satisfy all conditions and the sum of these is 23 tons. You can also use the ≥ and ≤ operators. =SUMIFS(A2:A13, B2:B13, "=2", C2:C13, ">=12/13/2012", C2:C13, "<=12/17/2012") returns 34, the number of tons of the commodity delivered during the same week that were rated 2. You can also use the ≥ and ≤ operators. =SUMIFS(A2:A13, B2:B13, "<>2", C2:C13, ">=12/10/2012", C2:C13, "<=12/20/2012") returns 29, the number of tons of the commodity delivered during any week that were not rated 2. You can also use the ≠, ≥, and ≤ operators. |
Example using REGEX |
---|
Given the following table: |
A | B | |
---|---|---|
1 | 45 | marina@example.com |
2 | 41 | Aaron |
3 | 29 | michael@example.com |
4 | 64 | jake@example.com |
5 | 12 | Sarah |
=SUMIFS(A1:A5, B1:B5,REGEX("([A-Z0-9a-z._%+-]+)@([A-Za-z0-9.-]+\.[A-Za-z]{2,4})",), A1:A5, ">10") returns 138, the sum of cells in A1:A5 that are larger than 10 and where the corresponding cell in B1:B5 contains an email address. |