how to count the Distinct value met specific condition

hamid sajjadi

New Member
Joined
Jan 6, 2018
Messages
7
Office Version
  1. 2019
Platform
  1. MacOS
Hello.
I have two simple columns as follow :

A B
city A 130
city A 170
city B 200
city A 300

I need to distinct count the city<200 . i.e =1.
how can I do this? i've tried many ways but got no answer :(
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
If you are looking for counts for each city, then try this...you can hardwire the 200 value into the formula if desired:
Book1
ABCDEF
1CityValueCity<thresholdCounts
2A130A2002
3A170B2000
4B200
5A300
Sheet1
Cell Formulas
RangeFormula
F2:F3F2=COUNTIFS($A$2:$A$5,D2,$B$2:$B$5,"<"&E2)
 
Upvote 0
It would help if you changed your profile to show what version of Excel you run because there are features in 365, for example, that could be used that aren't in earlier versions.

With 365, if I understand your issue, this might solve it:

Book1
ABCD
1City A1302002
2City A170
3City B200
4City A300
5City C600
6City X100
Sheet1
Cell Formulas
RangeFormula
D1D1=COUNTA(UNIQUE(FILTER(A1:A6,B1:B6<C1)))
 
Upvote 0
Sorry...I think I misunderstood your question. What I offered before gives a count for each city specified (green cells in example below), but it sounds like you want to count the number of unique cities that have values less than 200, which is what kweaver's solution does. If you don't have 365, the solution is more difficult (see the yellow cells below):
Book1
ABCDEF
1CityValueCity<thresholdCounts
2A130A2002
3A170B2000
4B200
5A300
6C6002002
7X100
Sheet1
Cell Formulas
RangeFormula
F2:F3F2=COUNTIFS($A$2:$A$5,D2,$B$2:$B$5,"<"&E2)
F6F6=SUM(--(FREQUENCY(IF($B$2:$B$7<E6,MATCH($A$2:$A$7,$A$2:$A$7,0)),ROW($A$2:$A$7)-ROW($A$2)+1)>0))
Press CTRL+SHIFT+ENTER to enter array formulas surrounded with curly braces.
 
Upvote 0
Solution
Sorry...I think I misunderstood your question. What I offered before gives a count for each city specified (green cells in example below), but it sounds like you want to count the number of unique cities that have values less than 200, which is what kweaver's solution does. If you don't have 365, the solution is more difficult (see the yellow cells below):
Book1
ABCDEF
1CityValueCity<thresholdCounts
2A130A2002
3A170B2000
4B200
5A300
6C6002002
7X100
Sheet1
Cell Formulas
RangeFormula
F2:F3F2=COUNTIFS($A$2:$A$5,D2,$B$2:$B$5,"<"&E2)
F6F6=SUM(--(FREQUENCY(IF($B$2:$B$7<E6,MATCH($A$2:$A$7,$A$2:$A$7,0)),ROW($A$2:$A$7)-ROW($A$2)+1)>0))
Press CTRL+SHIFT+ENTER to enter array formulas surrounded with curly braces.
thank you. it seems great. i have to try & expand this formula in my real senario.
 
Upvote 0
It would help if you changed your profile to show what version of Excel you run because there are features in 365, for example, that could be used that aren't in earlier versions.

With 365, if I understand your issue, this might solve it:

Book1
ABCD
1City A1302002
2City A170
3City B200
4City A300
5City C600
6City X100
Sheet1
Cell Formulas
RangeFormula
D1D1=COUNTA(UNIQUE(FILTER(A1:A6,B1:B6<C1)))
unfortunately i do not have office 365
 
Upvote 0
We're happy to help. Thanks for updating your profile and the feedback...and post back if you encounter any problems adapting the solution to your scenario.
 
Upvote 0

Forum statistics

Threads
1,214,614
Messages
6,120,519
Members
448,968
Latest member
Ajax40

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