COUNTIFS with multiple criteria

KuraiChikara

Board Regular
Joined
Nov 16, 2016
Messages
111
Office Version
  1. 2013
Platform
  1. Windows
I have an issue with COUNTIFS with multiple criteria. Example:

Column A has 4 John Doe’s
Column B has 4 fruits: Apple, Apple, Strawberry, Watermelon
Column C is my Formula: If I just include 1 countifs it works

=COUNTIFS($A$2:$A$5,D2,$B$2:$B$5,E2) returns 2 Apples found

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Name[/TD]
[TD]Fruit[/TD]
[TD]Formula[/TD]
[TD]Name[/TD]
[TD]Fruit[/TD]
[/TR]
[TR]
[TD]John Doe[/TD]
[TD]Apple[/TD]
[TD](enter here)[/TD]
[TD]John Doe[/TD]
[TD]Apple[/TD]
[/TR]
[TR]
[TD]John Doe[/TD]
[TD]Apple[/TD]
[TD][/TD]
[TD][/TD]
[TD]Strawberry[/TD]
[/TR]
[TR]
[TD]John Doe[/TD]
[TD]Strawberry[/TD]
[TD][/TD]
[TD][/TD]
[TD]Watermelon[/TD]
[/TR]
[TR]
[TD]John Doe[/TD]
[TD]Watermellon[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


However, if I wanted to find ALL fruit next to John Doe by including all options in the COUNTIFS (which adds to a total of 6 criteria; John Doe is looked at 3 times and there are 3 fruits specifically looked at), it returns 0

=COUNTIFS($A2:A$5,D2,$B$2:$B$5,E2,$A$2:$A$5,D2,$B$2:$B$5,E3,$A$2:$A$5,D2,$B$2:$B$5,E4)

For this example, I would want 4 to return because there are 4 fruits next to John Doe but it doesn’t.

Same result happens if I replace the Column E cell data in the formula with the actual text of the fruit.

=COUNTIFS($A2:A$5,D2,$B$2:$B$5,"Apple",$A$2:$A$5,D2,$B$2:$B$5,"Strawberry",$A$2:$A$5,D2,$B$2:$B$5,"Watermelon")

This also returns 0, when there are a total of 4 fruits in Column B.
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
So in this case you are kinda saying it not only has apple next to it but it also has strawberry and watermelon.... in the same cell which none of them do

What you wanna do is SUM the instance of each fruit

=SUM(COUNTIFS($A$2:$A$5,D2,$B$2:$B$5,E2),COUNTIFS($A$2:$A$5,D2,$B$2:$B$5,E3),COUNTIFS($A$2:$A$5,D2,$B$2:$B$5,E4))

This will be like summing 2 + 1 + 1 = 4

Try that
 
Last edited:
Upvote 0
That's exactly what I was looking for. Thank you.
I'm also proud of myself because I knew a SUM would fix the issue too, just didn't know how to incorporate it. You helped with that.
 
Upvote 0
Hi,

A couple of different ways to write the formula.

C2 formula Normally entered,
C3 formula to be confirmed by CSE, instructions below:


Book1
ABCDE
1NameFruitFormulaNameFruit
2John DoeApple4John DoeApple
3John DoeApple4Strawberry
4John DoeStrawberryWatermellon
5John DoeWatermellon
Sheet328
Cell Formulas
RangeFormula
C2=SUM(COUNTIFS(A2:A5,D2,B2:B5,{"Apple","Strawberry","Watermellon"}))
C3{=SUM(COUNTIFS(A2:A5,D2,B2:B5,E2:E4))}
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,021
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top