How to use SUMIF formula in Excel cell that must sum over a given range and instead of finding for a single value, it should find multiple values?
For finding a single value, I use:
=SUMIF(A4:A100;"1";B4:B100)
Now I need to sum over if the column A holds 1 or 2, like:
=SUMIF(A4:A100;"1" OR "2";B4:B100)
The cell A1 will hold the criteria as a text, here it would be 1;2.
It should return same as
=SUMIF(A4:A100;"1";B4:B100) + SUMIF(A4:A100;"2";B4:B100)
but I need a formula that can take any number of criteria (1,2,3,... or more).
What's the syntax? I'm not able to use VBA here.
To sum for 1 or 2 try this version
=SUM(SUMIF(A4:A100;{1;2};B4:B100))
SUMIF will return an "array" of two results so you need SUM to sum that array for the total for 1 and 2
You can add as many numbers as you like e,g,
=SUM(SUMIF(A4:A100;{1;2;3;4};B4:B100))
or with numbers listed in a range like Z1:Z10
=SUMPRODUCT(SUMIF(A4:A100;Z1:Z10;B4:B100))
I don't think there is a way to do OR within a single statement like this. You can use SUMIFS for multiple conditions where all need to be true, but in this case you would just need to add together multiple SUMIF statements:
=SUMIF(A4:A100,"1",B4:B100)+SUMIF(A4:A100,"2",B4:B100)
Since "1" and "2" are mutually exclusive:
=SUMIF(A4:A100,"1",B4:B100)+SUMIF(A4:A100,"2",B4:B100)
i think you should define a range, let's say keys where you keep all values for which you want to sum. so in this range you keep 1 and 2 and can modyfy it whenever you want. then you add a flag column with formula IFERROR(IF(MATCH(A4,keys,0)>0,1,0),0) - now you have column in which 1 is for the values you want to sum.
this works with multiple text evaluation
=sumif(M4:M206,"Sat",O4:O206)+sumif(M4:M206,"Sun",O4:O206) // add here more + + +
Related
I need to use SUMIFS function or other excel functions to find the requirement that I need!
For example, I need the value of Cat 1 & Cat 22 so the returning value should be $19,152.
Any advice?
You can't use sumifs since you searching for one value row wise and the other value column wise.
=SUMPRODUCT(B2:F5,(B1:F1="Cat 1")*(A2:A5="Cat 22"))
Or if you want to find it with index + match, enter it with Ctrl + Shift + Enter:
{=INDEX(B2:F5,MATCH(1,--(A2:A5="Cat 22"),0);MATCH(1,--(B1:F1="Cat 1"),0))}
If you Name all your rows and columns, you can use simply, for example:
=Cat_1 Cat_22
=Cat_2 Cat_44
The space between the two named ranges is the Intersect operator, and so returns the cell at the intersection of the two ranges.
You don't really have to use Name'd ranges (you could use the range references), but it makes visualization of what you are doing easier.
And if you want to find the sum of multiple intersections, you can just use the addition operator or the Sum function on multiple intersections.
eg: =SUM(Cat_1 Cat_33, Cat_3 Cat_33)
I'm trying to use the COUNTIFS statement to count all rows where values in 4 different columns equal "something", while excluding rows where the values in two columns are equal. This is what I have for counting the rows where the 4 columns equal "something" but I can't figure out how to add the last part:
=COUNTIFS(A2:A100,"something",B2:B100,"something",C2:C100,"something",D2:D100,"something", [...])
Now I need to add another statement within this COUNTIFS at the [...] that says something like "exclude all rows where value in J is equal to value in K", but I can't seem to figure out how to do that WITHIN the COUNTIFS statement.
You likely have to move to a SUMPRODUCT function.
=SUMPRODUCT((A2:A100="something")*(B2:B100="something")*(C2:C100="something")*(D2:D100="something")*(J2:J100<>K2:K100))
Avoid full column references in SUMPRODUCT due to the cyclic nature of the calculation.
You could use an Array function for this.
={sum((A1:A1000 = 'Something')*(BB:B1000 = 'Something')*(C1:C1000 = 'Something')*(D1:D1000 = 'Something')*(J1:J1000 = K1=K1000))}
for entering an array function, you need to use Ctrl+Shift+Enter
More info at Excel Array Functions
I want to get the sum of values represented by 1,2,3,4
eg: =SUMIF(D5:D23,"1",G5:G23)+SUMIF(D5:D23,"2",G5:G23)+SUMIF(D5:D23,"3",G5:G23)+SUMIF(D5:D23,"4",G5:G23)
How can I do this operation? Please help me.
You want to use SUMIFS:
=SUMIFS(G5:G23,D5:D23,">0",D5:D23,"<5")
You want to sum all values from G5:G23 where the value from D5:D23 is greater than 0 and less than 5. So you require 2 criteria. >0 and <5.
Here is the function:
SUMIFS(sum_range,criteria_range1,criteria1,sum_range,[criteria_range2,criteria2],...)
Example:
Edit
Is think you want a vertical lookup - VLOOKUP()
Formulas:
G6: =VALUE(VLOOKUP(D6,$B$25:$E$30,2,FALSE))
H6: =IFERROR(IF(SEARCH("Valve",VLOOKUP(D6,$B$25:$E$30,3,FALSE))>0,$D$23,0),0)
I6: =E6*$D$22
J6: =SUM(G6:I6)
Now select G6:J6, grab the handle at the bottom right, and drag to fill rows G7:J7 to G20:J20.
Now sum up all the columns.
Here is the file completed: http://www.filedropper.com/wpmccardiocosts_1
You should check this out, it is very handy: http://www.mbaexcel.com/excel/tutorial-how-to-decide-which-excel-lookup-formula-to-use/
It may be simpler to use an array entered formula using SUM and IF:
=SUM(IF(D3:D23={1,2,3,4},G3:G23))
entered using [ctrl]+[shift]+[enter] (an array formula)
This will allow for use of many variables in place of 1,2,3,4 such as not continuous numbers, text ect.
I'm struggling with integrating a condition into my COUNTIFS statement. I have about 5 conditions which I've been able to easily work in, but I can't figure out the last one. The criteria range would be A1:A40000, and the criteria would count the number that match any value in a list of 30 text strings on Sheet 2, Cells A1:A40. Is this possible? I can get the result without the other conditions. Unfortunately, I do not have the flexibility to add a column next to A1:A40000 that checks to see if it is in the list.
Edit: Clarification per request.
Simplified version of what I'm doing. I need to count the number items (column A) that meet several conditions depending on the column in the entire data set. So, I need to find the number of items that have a value of "1" in column B - AND - a value of "YES" in column "C" - AND - a value of "OLD" in column "D" - AND - (the part I'm struggling with) column "E" must contain any one of the values that's in a completely separate range (call it Z1:Z40). The formula for the first 3 conditions would be:
=COUNTIFS(B:B,1, C:C,"YES", D:D,"OLD")
The final criteria in bold would be something like:
=COUNTIFS(B:B,1, C:C,"YES", D:D,"OLD", **E:E,isnumber(match(E:E,Z1:Z40,0))**)
But that does not work...
You can simply use the range as a criteria. If you do that then your COUNTIFS function will return an array (one value each for each value in Z1:Z40) so you need a function to sum that array - I use SUMPRODUCT because it doesn't require array entry
=SUMPRODUCT(COUNTIFS(B:B,1,C:C,"yes",D:D,"old",E:E,Z1:Z40))
That approach has some limitations - you can only use two "multi-item" criteria in one COUNTIFS function (and if you do one must be a column, the other a row, or you need to use TRANSPOSE to make it that way), and items in Z1:Z40 should not be repeated (or you may get double counting).
To overcome either of those limitations you can use SUMPRODUCT in place of COUNTIFS - with ISNUMBER(MATCH for the multi-item criterion. If you use SUMPRODUCT like that then it's better to restrict the ranges for efficiency reasons, e.g.
=SUMPRODUCT((B2:B100=1)*(C2:C100="yes")*(D2:D100="old")*ISNUMBER(MATCH(E2:E100,Z1:Z40,0)))
You can add as many ISNUMBER(MATCH criteria as you want and Z1:Z40 can be any single row/column range
Let's say all your headers are in row 1 and the real data starts in row 2.
I would add a column on the end and put in the formula
=IF(AND(B2=1, C2="YES", D2="OLD", COUNTIF($Z$1:$Z$40,E2)),"YES","NO")
Then copy that down and any row where Column F was "YES" is a row that met all the criteria.
There is also a way to use wildcards
=countifs(A1:D1;"*yes")
which counts all cell which contain 'yes'
I am using excel 2002 to create a spreadsheet. What I am trying to do is use the countif function but I have more than one condition. So I have 2 columns with a list of numbers and what I want to say is count the number of occurences where the number x is in one column and the number y is in the other column (in the same row).
E.g.
1 1
1 1
1 2
2 2
2 3
3 3
So if in the above I wanted to count the rows where the first column had the number 1 and the second column had the number 2, the answer should be 1.
I can't use the COUNTIF function because that only allows you to specify one condition and the COUNTIFS isn't available because I am using excel 2002.
Please Help.
This is a job for an array formula. In your case you can do:
=SUM((A1:A6=1)*(B1:B6=2))
entered as an array forumla (Ctrl-Shift-Enter)
The equality tests each return an array of boolean values, and the multiplication does an element-wise multiply (so a logical AND in this case). SUM coerces booleans to numbers when it adds up the resulting array.
EDIT:
In an answer to this similar question:
https://stackoverflow.com/questions/576569/use-2-conditions-in-excel-sumif
Jon Fournier posted a link to:
http://www.cpearson.com/excel/ArrayFormulas.aspx
which has a lot more detail on this sort of thing.
You could create a 3rd column which joins the two other column values with (say) a space or other special character, and then test for the combined value with COUNTIF.
If you don't want to add another column on your worksheet, you could put it on a different worksheet - or even create a dynamic named range.
Personally I love the SUMPRODUCT function but I'm not sure if you have it in Excel2002
Here's a very good resource for multiple conditions:
http://www.ozgrid.com/Excel/sum-if.htm
The DCOUNT function allows for multiple criteria.
The formula would look like this
=DCOUNT(A2:B8,"ColumnA",A11:B12)
if you have your criteria below the data.
Screenshot of data and formula http://img31.imageshack.us/img31/1093/dcount.png