Count unique text entries with multiple criteria

meowerson

New Member
Joined
Nov 14, 2014
Messages
5
I am trying to count unique text 'Species' entires in column 'C' on a separate Worksheet (within the same workbook) with multiple criteria. The data are organized as follows (in 'Worksheet'):

Row#ABC
1SurveySiteSpecies
2
1
ax
31by
41by
52ax
62ax
72bz
83az
93bx

<tbody>
</tbody>

I have attempted to calculate the number of unique 'Species' during survey '1' at site 'a' using the following formula:
=SUM(IF('Worksheet'!$B$2:$B$9="a")*('Worksheet'!$A$2:$A$9="1", 1/(COUNTIFS('Worksheet'!$B$2:$B$9, "a", 'Worksheet'!$C$2:$C$9, 'Worksheet'!$C$2:$C$9, 'Worksheet'!$C$2:$C$9, "1"))), 0)

but it says there is an error in my formula. Please help!

Thanks,
meowerson

<colgroup><col width="75" style="width:75pt"></colgroup><tbody>
<!--EndFragment-->
</tbody>
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Try...

=SUM(IF((Worksheet!$B$2:$B$9="a")*(Worksheet!$A$2:$A$9=1), 1/(COUNTIFS(Worksheet!$B$2:$B$9,"a",Worksheet!$A$2:$A$9,1,Worksheet!$C$2:$C$9,Worksheet!$C$2:$C$9))))

...confirmed with CONTROL+SHIFT+ENTER. Although, the following should be more efficient...

=SUM(IF(FREQUENCY(IF(Worksheet!A2:A9=1,IF(Worksheet!B2:B9="a",IF(Worksheet!C2:C9<>"",MATCH("~"&Worksheet!C2:C9,Worksheet!C2:C9&"",0)))),ROW(Worksheet!C2:C9)-ROW(Worksheet!C2)+1)>0,1))

...also confirmed with CONTROL+SHIFT+ENTER.

Hope this helps!
 
Upvote 0
Hello Domenic,

Thanks very much for your help but neither formula you suggested worked for me. I had simplified my dataset for the purposes of this forum, but perhaps there is something about my data that is causing the problem. Here is a truer summary that I hope will shed some light (the worksheet is called 'PC Breeders' and has 1357 rows including the column heading):

Row #D LM
1SurveySiteSpecies
21ducx01CBCH
31ducx01HETH
41sneco02CBCH
51sneco02CBCH
62ducx01AMRO
72ducx01VATH
82sneco02AMRO
92sneco02CBCH
103ducx01GCKI
113ducx01GCKI
123ducx01AMRO
133sneco02CBCH
143sneco02CBCH
...
13573sneco02VATH

<tbody>
</tbody>

Not sure if the combination of text+numbers in column L (site) might be a problem?
 
Upvote 0
Hello Domenic,

Thanks very much for your help but neither formula you suggested worked for me. I had simplified my dataset for the purposes of this forum, but perhaps there is something about my data that is causing the problem. Here is a truer summary that I hope will shed some light (the worksheet is called 'PC Breeders' and has 1357 rows including the column heading):

Row #
D
L
M
1
Survey
Site
Species
2
1
ducx01
CBCH
3
1
ducx01
HETH
4
1
sneco02
CBCH
5
1
sneco02
CBCH
6
2
ducx01
AMRO
7
2
ducx01
VATH
8
2
sneco02
AMRO
9
2
sneco02
CBCH
10
3
ducx01
GCKI
11
3
ducx01
GCKI
12
3
ducx01
AMRO
13
3
sneco02
CBCH
14
3
sneco02
CBCH
...
1357
3
sneco02
VATH

<TBODY>
</TBODY>

Not sure if the combination of text+numbers in column L (site) might be a problem?

When Survey = 3 and Site = ducx01, you expect a species count of 2, right?
 
Upvote 0
Yes, Aladin, that is correct.

I'm sure Domenic proposed the same set up. Control+shift+enter, not just enter:
Rich (BB code):
=SUM(IF(FREQUENCY(IF($D$2:$D$1357=3,IF($L$2:$L$1357="duckx01",
  IF($M$2:$M$1357<>"",MATCH("~"&$M$2:$M$1357,$M$2:$M$1357&"",0)))),
  ROW($M$2:$M$1357)-ROW($M$2)+1),1))
 
Upvote 0
Hi Aladin,

Thanks again, but it's still not working. I get a #VALUE! message. Note that I am referencing cells on a different worksheet and am putting the reference to that worksheet (written as: 'PC Breeders'!) before every range in the formula. Would this affect your suggested formula in any way?
 
Upvote 0
Hi Aladin,

Thanks again, but it's still not working. I get a #VALUE! message. Note that I am referencing cells on a different worksheet and am putting the reference to that worksheet (written as: 'PC Breeders'!) before every range in the formula. Would this affect your suggested formula in any way?

Control+shift+enter ---> Press down the control and the shift keys at the same while you hit the enter key. When done properly, Excel automatically encloses the target formula between curly braces, i.e., between { and }.
 
Upvote 0
This is not a single formula, rather a workaround to get the result required. Try it if there is not a more suitable solution available.
Enter in D2:


=A2&B2&c2


Copy col D and paste special in col E as Value, then remove duplicates in this column.
Enter in cell F2:


=COUNTIF($E$2:$E$14;(LEFT(E2;LEN(E2)-4))&"*")


enter in cell G2:


=LEFT(E2;LEN(E2)-4)


Copy col F and G and paste special as Value in col H and I.
Select col H and I, then remove duplicates in col I.


If it works for you, you can find the Survey+Site group in col I, the number of their unique species in col H.
If the data is in different worksheets, change the references accordingly.
 
Upvote 0
This is not a single formula, rather a workaround to get the result required. Try it only if there is not a more suitable solution available.
Enter in D2:
=A2&B2&c2
Copy col D and paste special in col E as Value, then remove duplicates in this column.
Enter in cell F2:
=COUNTIF($E$2:$E$14,(LEFT(E2,LEN(E2)-4))&"*")
Enter in cell G2:
=LEFT(E2,LEN(E2)-4)

Copy col F and G and paste special them as Value in col H and I.
Select col H and I, then remove duplicates in col I.
If it works for you, you can find the Survey+Site group in col I, the number of their unique species in col H.
If the data is in different worksheets, change the references accordingly.
Excel Workbook
ABCDEFGHI
1SurveySiteSpeciesNo of unique speciesVersion
21ducx01CBCH1ducx01CBCH1ducx01CBCH21ducx0121ducx01
31ducx01HETH1ducx01HETH1ducx01HETH21ducx0111sneco02
41sneco02CBCH1sneco02CBCH1sneco02CBCH11sneco0222ducx01
51sneco02CBCH1sneco02CBCH2ducx01AMRO22ducx0122sneco02
62ducx01AMRO2ducx01AMRO2ducx01VATH22ducx0123ducx01
72ducx01VATH2ducx01VATH2sneco02AMRO22sneco0213sneco02
82sneco02AMRO2sneco02AMRO2sneco02CBCH22sneco02
92sneco02CBCH2sneco02CBCH3ducx01GCKI23ducx01
103ducx01GCKI3ducx01GCKI3ducx01AMRO23ducx01
113ducx01GCKI3ducx01GCKI3sneco02CBCH13sneco02
123ducx01AMRO3ducx01AMRO
133sneco02CBCH3sneco02CBCH
143sneco02CBCH3sneco02CBCH
Sheet
 
Upvote 0

Forum statistics

Threads
1,214,975
Messages
6,122,538
Members
449,088
Latest member
RandomExceller01

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