How to count all the items in 2 columns depending on comparison?

1

I have two columns with data and I'd like to count all the rows where the value in the first column are greater than the values in the second column.

The best I could find was using cell references, something like this:

=COUNTIF($D$2:$D$289, ">"&$E$2)

but obviously it is not what I need.

However, I did try the following:

=COUNTIF($D$2:$D$289, ">"&$E$2:$E$289)

but I get an error...

Can you advise please?

Thanks.

enter image description here

dushkin

Posted 2018-07-20T14:58:03.657

Reputation: 197

Answers

2

In order to compare the ranges the way you want, you have to use a formula that will give you a cell-by-cell comparison. For this solution, use SUMPRODUCT.

For Excel:

=SUMPRODUCT(--($D$2:$D$289>&$E$2:$E$289))

How it works is that the inner comparison $D$2:$D$289>&$E$2:$E$289 will generate an array of TRUE/FALSE values. The -- part of the formula converts all the TRUEs and FALSEs into a array of 1 and 0. Finally the SUMPRODUCT simply sums up all the ones in the array.

For Google Sheets it's simply:

==SUMPRODUCT($D$2:$D$289>&$E$2:$E$289)

Results given the example data from OP:

enter image description here

PeterT

Posted 2018-07-20T14:58:03.657

Reputation: 247

Thank you Peter. I get an "Error parsing formula" error message. Maybe that's because I work on Google Spreadsheets?? – dushkin – 2018-07-20T15:31:12.090

@dushkin then you should not tag with Excel. – Scott Craner – 2018-07-20T16:15:22.660

@duskin, see update answer – PeterT – 2018-07-20T16:36:57.633

@ScottCraner Scott, since there is much common between the two, I was hoping the excel guys could help me as well. – dushkin – 2018-07-20T16:44:54.993

@PeterT I made the change. Still Error (as you may see in the question image I've uploaded)... I also tried it on a separate other very tiny range of two columns - and still error... :( – dushkin – 2018-07-20T16:47:01.513

I used your example data and the SUMPRODUCT formula works for me. See above. – PeterT – 2018-07-20T17:49:12.423

@PeterT Peter, the final formula should have only single = instead of two as in you answer for google :) Thanks a lot! – dushkin – 2018-07-20T18:05:32.180