Reputation: 8220
I m using SUMIF
formula to get the sum of rows which include a specific text, Test
. However, I want to sum up only rows which do not include the color Red
.
Currently I m using the below formula:
=SUMIF(A1:A6;"*Test*";B1:B6)-SUMIFS(B1:B6;A1:A6;"*Test*";A1:A6;"*Red*")
Is there a better/clearer formula?
Test | 1 |
---|---|
Test 1 Red | 2 |
Test 2 | 3 |
Test 1 Red | 4 |
Test 1 Blue | 5 |
Test 3 | 6 |
Upvotes: 0
Views: 107
Reputation: 27243
Try using the following formula, exclude the part you don't need in the criteria itself using wildcard:
=SUMIF(A1:A6,"<>*Red*",B1:B6)
Or,
=SUM((ISNA(TEXTBEFORE(A1:A6," Red")))*B1:B6)
Or, to include the word Test and not Red, then SUMIFS()
=SUMIFS(B1:B6,A1:A6,"<>*Red*",A1:A6,"*Test*")
With multiple criteria to Exclude:
=SUM((ISNA(TEXTBEFORE(A1:A6,{" Red"," Blue"})))*B1:B6)
Or using SUMIFS()
+SUM()
=SUM(B1:B6)-SUM(SUMIFS(B1:B6,A1:A6,{"*Red","*Blue"}))
=SUMIF(A1:A6,"Test*",B1:B6)-SUM(SUMIFS(B1:B6,A1:A6,{"*Red","*Blue"},A1:A6,"Test*"))
Instead of hard-coding, its better to use cell references so it becomes more dynamic and one can toggle around whenever a color is required or not:
=SUMIF(A1:A11,"Test*",B1:B11)-SUM(SUMIF(A1:A11,"*"&List[List],B1:B11))
Upvotes: 1
Reputation: 2614
The SUMIFS function, one of the math and trig functions, adds all of its arguments that meet multiple criteria
This may be the easiest (sum range ANDing criteria).
=SUMIFS(B2:B7, A2:A7, "*Test*", A2:A7, "<>*Red*", A2:A7, "<>*Blue*")
Do you want to 'OR' matches (for example, "Apples" OR "Oranges") later?
Upvotes: 0