Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CountifS + multiple criteria + distinct count

I'm looking for a formula calculating : distinct Count + multiple criteria Countifs() does it but do not includes distinct count...

Here is an example.

I have a table on which I want to count the number of distinct items (column item) satisfying multiple conditions one column A and B : A>2 and B<5.

Image description here

enter image description here

Line  Item  ColA  ColB
1     QQQ    3     4
2     QQQ    3     3
3     QQQ    5     4
4     TTT    4     4
5     TTT    2     3
6     TTT    0     1
7     XXX    1     2
8     XXX    5     3
9     zzz    1     9

Countifs works this way : COUNTIFS([ColumnA], criteria A, [ColumnB], criteria B)

COUNTIFS([ColumnA], > 2 , [ColumnB], < 5)

Returns : lines 1,2,4,5,8 => Count = 5

How can I add a distinct count function based on the Item Column ? :

lines 1,2 are on a unique item QQQ

lines 4,5 are on a unique item TTT

Line 8 is on a unique item XXX

Returns Count = 3

How can I count 3 ?!

Thanks

You can download the excel file @ Excel file

like image 794
Vincent Avatar asked Jun 23 '16 12:06

Vincent


People also ask

How do you count only unique values in Excel with Countifs?

In this case, you can use a combination of SUM, IF and COUNTIF functions to count unique values in Excel. To count unique values, enter the formula =SUM(IF(COUNTIF(range, range)=1,1,0)) in the desired cell. The range denotes the starting cell and the ending cell.

How do I count multiple unique values in Excel?

You can use the combination of the SUM and COUNTIF functions to count unique values in Excel. The syntax for this combined formula is = SUM(IF(1/COUNTIF(data, data)=1,1,0)). Here the COUNTIF formula counts the number of times each value in the range appears.

Can I use Countifs with multiple criteria?

How to Use Multiple Criteria in Excel COUNTIF and COUNTIFS Function. Excel has many functions where a user needs to specify a single or multiple criteria to get the result. For example, if you want to count cells based on multiple criteria, you can use the COUNTIF or COUNTIFS functions in Excel.


1 Answers

Newer versions of Excel allow for this problem to be solved in a (relatively) more simple way. It certainly is easier to follow and understand, conceptually.

First, filter the table based on multiple criteria (join multiple with the *):

=FILTER(Table,(Table[Column A]>2)*(Table[Column B]<5))

screenshot1

Then, grab the "Item" column with INDEX:

=INDEX(FILTER(Table,(Table[Column A]>2)*(Table[Column B]<5)),,2)

screenshot2

Next, filter for unique entries:

=UNIQUE(INDEX(FILTER(Table,(Table[Column A]>2)*(Table[Column B]<5)),,2))

screenshot3

Finally, perform a count:

=COUNTA(UNIQUE(INDEX(FILTER(Table,(Table[Column A]>2)*(Table[Column B]<5)),,2)))

screenshot4

like image 131
Brian Johnson Avatar answered Sep 28 '22 19:09

Brian Johnson