How can I use COUNTIFS for multiple criteria? - excel

I want to be able to use the COUNTIFS formula for multiple criteria.
For example:
1,Banana
2,Orange
1,Banana
2,Orange
I want to use COUNTIFS to count how many occurrences of 1 is associated with banana and how many times 2 is associated with orange.
I'm thinking of =COUNTIFS(A:A,1,B:B,"Banana")+=COUNTIFS(A:A,2,B:B,"Orange")
This would supposedly equal 4, but I know that formula is wrong and I don't know how to format it.
If this is not possible, then I'd have to use two of the same formulas and add them together, but I'm looking for a better way and just use one formula.
How do I go about this problem, any help would be greatly appreciated.
Thank you.
EDIT: =COUNTIFS(A:A,1,B:B,"Banana",A:A,2,B:B,"Orange") returns 0 for some reason, why is that?

You can try SUMPRODUCT function instead:
=SUMPRODUCT(((B:B="Orange")+(B:B="Banana"))*(A:A=1))
To add additional criteria value, you need to add it to the rest, for example - adding Apples criteria:
=SUMPRODUCT(((B:B="Orange")+(B:B="Banana")+(B:B="Apple"))*(A:A=1))
Similar logic needs to be used to add another criteria range, for example:
=SUMPRODUCT(((B:B="Orange")+(B:B="Banana"))(A:A=1)(C:C="X"))
Hope it helped.
EDIT: Just saw question adjustment. In that case you should use following logic:
=SUMPRODUCT((B:B="Orange")(A:A=1)+(B:B="Banana")(A:A=2))

your formula should be
=COUNTIFS(A:A,1,B:B,"Banana")+COUNTIFS(A:A,2,B:B,"Orange")

Related

lookup with multiple conditions and for rows

Hello sages from StackOverflow,
I'm in search of a formula that can relate 3 diferent conditions, I tried using some IF statemets with the TEXTJOIN formula but I find myself lost in the way,
I got a data base just like this (image below), just a much bigger one, I want to search for a key like MCAA01 and obtain the doc's that have in front of it a "NO" all in one cell, like if you use the formula TEXTJOIN("/",...
My problem is that I cannot find a way to relate the whole column of the doc's with the key,
I tried something like TEXTJOIN("/",TRUE,IF(2ndIMAGE!A2=1stIMAGE!B1,IF(B2="no",1stIMAGE!A2,""),""))
This does give a result but it's just 1 thing, not whole answer
please sages of StackOverflow, you're my only hope. Thank you!
You need FILTER() then TEXTJOIN().
=TEXTJOIN("/",TRUE,FILTER($A$2:$A$4,FILTER($B$2:$H$4,$B$1:$H$1=$B8)="No",""))
If your version of excel supports LAMBDA() function then you can try below formula and you do not need to drag the formula to each cell. It will spill results automatically.
=BYROW(B8:B14,LAMBDA(a,TEXTJOIN("/",TRUE,FILTER(A2:A4,FILTER(B2:H4,B1:H1=a)="No",""))))

Excel Sumif formula

I am trying to create a SumIf formula that adds multiple columns together based on one criteria.
=sumif(F$8:F$58,F73,L$8:L$58+I$8:I$58)
This is giving me an error and will not add the two columns together.
You'd need
=sumif(F$8:F$58,F73,L$8:L$58) + sumif(F$8:F$58,F73,I$8:I$58)
I highly recommend you make it a practice to use SUMIFS instead of SUMIF even if you only have one criteria. The order makes more sense (what you're summing first), and it scales easier. Say you want to start adding more criteria, now you'll have to readjust the order of the inputs, whereas with Sumifs you simply just add to the criteria.
=sumifs(L$8:L$58,F$8:F$58,F73) + sumifs(I$8:I$58,F$8:F$58,F73)
In case of summing multiple ranges, you can also try SUMPRODUCT
=SUMPRODUCT((F$8:F$58=F73)*((L$8:L$58)+(I$8:I$58)))
The logic is similar to SUMIFS, (F$8:F$58=F73) sets the criteria while ((L$8:L$58)+(I$8:I$58)) defines the range to be summed.
Let me know if you have any questions. Cheers :)

Sum with multiple Sum ranges for criteria in multiple criteria ranges

I need to sum using more than one sum range for a criteria matching in more than on criteria range.
Sample:
I have tried searching solution to me problem but couldn't find.
I am not sure how should I be asking related question here, I am just attaching an image just i did earlier.
enter image description here
SUMIFS requires that the ranges be the same size so you can do:
=SUMIFS(B:D,A:C,G2)
Or you can add two SUMIFS together:
=SUMIFS(B:B,A:A,G2)+SUMIFS(D:D,C:C,G2)
Finally I was able to achieve solution to the situation,
solution:
=SUM(IF(A1:C6=H2,IF(E1:E6=H3,B1:D6)))
Regards..

Excel - SUMIFS for multiple columns

I need to sum the values of several columns, if other cells in the same row match a predefined criteria. The working formula for only 3 columns is the following:
=SUM(SUMIFS(‘Sheet1'!W:W; ‘Sheet1'!$B:$B;"Sales";‘Sheet1'!$C:$C;">=4");SUMIFS(‘Sheet1'!X:X; ‘Sheet1'!$B:$B;"Sales";‘Sheet1'!$C:$C;">=4");SUMIFS(‘Sheet1'!Y:Y; ‘Sheet1'!$B:$B;"Sales";‘Sheet1'!$C:$C;">=4"))
I will need to use the formula for several cells (and sum more than 10 columns per time) and I will need to change the columns manually, so I need the same formula in the following way:
=SUMIFS(‘Sheet1'!W:Y; ‘Sheet1'!$B:$B;"Sales";‘Sheet1'!$C:$C;">=4")
,but currently this formula leads to a "#VALUE!" error. The reason for that is (I assume) the use of multiple columns "W:Y"
Can you suggest a workaround?
I would suggest to use SUMPRODUCT rather than SUMIFS. You can build something like that :
=SUMPRODUCT((B1:B1048575="Sales")*(C1:C1048575>=4)*(W1:Y1048575))
The downside of SUMPRODUCT is that you can't use a whole column (for example you cannot write SUMPRODUCT((B:B="Sales"...)), this would generate an error).
Hope this helps.
I suggest you add a column with the sum('sheet1'!W:Y) and then use sumifs on this columns. It is a two step way but it will give the result you expect
Here's what I have :)
=SUM(SUMIFS('WTD Raw'!R:R,'WTD Raw'!E:E,"Kindle-Customer Care",'WTD
Raw'!J:J,"Week27",'WTD Raw'!H:H,'PassRate | July'!G8) + SUMIFS('WTD
Raw'!R:R,'WTD
Raw'!E:E,"Kindle-Technical Support",'WTD Raw'!J:J,"Week27",'WTD
Raw'!H:H,'PassRate | July'!G8))
Instead of using ";" use the Mathematical Operators for it to work.

Count rows with specific property

I have the following table:
I only want to count each rows which look like that: K,0,1
I tried
=AND(COUNTIF(A:A;"K");COUNTIF(B:B;0);COUNTIF(C:C;1))
However that only gives me a boolean value back and does not count?
I really appreciate your suggestions!
COUNTIFS extends the usefulness of the COUNTIF function by allowing you to specify from 2 to 127 criteria rather than just one as in COUNTIF.
COUNTIFs(A:A;"K";B:B;0;C:C;1) It should work fine. And solution is already stated by simoco via comment.
Let me know, if it works.

Resources