countifs question

backsidedriver

New Member
Joined
Mar 1, 2023
Messages
2
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
Platform
  1. Windows
I am struggling with countifs. Perhaps I am not using it properly. Here is my scenario.

I want to count cells only if column A = "Applications", column B = "Yes", and column C = column D for each row in a range. Here is my example data

ABCD
ApplicationsYesWebWeb
ApplicationsNoWindows ClientWeb
DatabaseYesOracleOracle
DatabaseYesOracleOracle
ServerNoLinuxLinux
ServerNoLinuxWindows
ApplicationsYesWebWindows Client

With the above data I expect the count to be equal "1" since there is only one row where all the critera matches. However, I seem to get different answers. I have used the following:

=countifs(A:A,"Applications",B:B,"Yes",C:C,D:D)
and
=countifs(A:A,"Applications",B:B,"Yes",C:C,"="&D:D)

Should this work or am I using the wrong formula?

Thanks in advance for your advice.
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Welcome to the MrExcel board!

Here are a couple of options, depending on which of your Excel versions it needs to work in. You can use larger ranges than I have but I strongly recommend not using whole column references.

23 03 01.xlsm
ABCDEF
1ApplicationsYesWebWeb1
2ApplicationsNoWindows ClientWeb1
3DatabaseYesOracleOracle
4DatabaseYesOracleOracle
5ServerNoLinuxLinux
6ServerNoLinuxWindows
7ApplicationsYesWebWindows Client
8
9
10
Count
Cell Formulas
RangeFormula
F1F1=IFNA(ROWS(FILTER(A1:A10,(A1:A10="Applications")*(B1:B10="yes")*(C1:C10=D1:D10),NA())),0)
F2F2=SUMPRODUCT(--(A1:A10="Applications"),--(B1:B10="Yes"),--(C1:C10=D1:D10))
 
Upvote 0
Welcome to the MrExcel board!

Here are a couple of options, depending on which of your Excel versions it needs to work in. You can use larger ranges than I have but I strongly recommend not using whole column references.

23 03 01.xlsm
ABCDEF
1ApplicationsYesWebWeb1
2ApplicationsNoWindows ClientWeb1
3DatabaseYesOracleOracle
4DatabaseYesOracleOracle
5ServerNoLinuxLinux
6ServerNoLinuxWindows
7ApplicationsYesWebWindows Client
8
9
10
Count
Cell Formulas
RangeFormula
F1F1=IFNA(ROWS(FILTER(A1:A10,(A1:A10="Applications")*(B1:B10="yes")*(C1:C10=D1:D10),NA())),0)
F2F2=SUMPRODUCT(--(A1:A10="Applications"),--(B1:B10="Yes"),--(C1:C10=D1:D10))
Thank you for the reply. The first option with, my version of excel (2016), does not support the "FILTER" option. However the second option appears to work except the count is short by 1 in one case but an exact match in another. It is close enough for may needs. Thank you again.
 
Upvote 0
Thank you for the reply. The first option with, my version of excel (2016), does not support the "FILTER" option.
You should update your profile to accurately display the version on Excel you have, so solutions can be tailored to your version.
That is what that field is for, it lets helpers know what version of Excel you are using so they can be sure to come up with solutions that will work for you on your current version of Excel.

1677686327262.png
 
Upvote 0
However the second option appears to work except the count is short by 1 in one case but an exact match in another. It is close enough for may needs.
I don't understand what is the problem with Peter's formula.

The formula works for your requirement:
With the above data I expect the count to be equal "1" since there is only one row where all the critera matches.

I take this opportunity to give you the correction of post #3 and another option with a array formula, to show how it works with the Count function:

Dante Amor
ABCDEF
1ApplicationsYesWebWeb2
2ApplicationsNoWindows ClientWeb2
3DatabaseYesOracleOracle2
4DatabaseYesOracleOracle
5ServerNoLinuxLinux
6ServerNoLinuxWindows
7ApplicationsYesWindows ClientWindows Client
Hoja5
Cell Formulas
RangeFormula
F1F1=SUMPRODUCT(--(A1:A10="Applications"),--(B1:B10="Yes"),--(C1:C10=D1:D10))
F2F2=SUMPRODUCT((A1:A10="Applications")*(B1:B10="Yes")*(C1:C10=D1:D10))
F3F3=COUNT(IF((A1:A10="Applications")*(B1:B10="Yes")*(C1:C10=D1:D10),1))
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
except the count is short by 1 in one case
Quite likely the problem is that the data contains one or more stray leading or trailing spaces (or could be multiple consecutive internal spaces).
For example, with the data below, visually it looks like the result should be 2 (rows 1 and 7) but the formula I gave above (cell F2) is only returning 1 and that is because in this example, cell D1 has a space character after the word Web and C1 does not.

A formula like I have in F3 below might help identify if the issue does relate to stray space characters.

23 03 01.xlsm
ABCDEF
1ApplicationsYesWebWeb
2ApplicationsNoWindows ClientWeb1
3DatabaseYesOracleOracle2
4DatabaseYesOracleOracle
5ServerNoLinuxLinux
6ServerNoLinuxWindows
7ApplicationsYesWindows ClientWindows Client
8
9
10
Count
Cell Formulas
RangeFormula
F2F2=SUMPRODUCT(--(A1:A10="Applications"),--(B1:B10="Yes"),--(C1:C10=D1:D10))
F3F3=SUMPRODUCT(--(TRIM(A1:A10)="Applications"),--(TRIM(B1:B10)="Yes"),--(TRIM(C1:C10)=TRIM(D1:D10)))


And yes, please fix your profile as suggested above by @Joe4
 
Upvote 0
However the second option appears to work except the count is short by 1 in one case but an exact match in another
If you have problems with your data, as Peter suggests, and you don't have the Unique function, you can obtain a pivot table of each column and thus identify which texts you have problems, see the following example, the ones marked in yellow should be values Unique, but appear more than once. In this way you will be able to identify in which texts you have problems, correct them and use the formulas. Since the best practice is to have a clean database.

1677769762527.png
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,559
Members
449,089
Latest member
Motoracer88

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