Counting distinct values based on two criteria one of which should be a range

youreskimofriend

New Member
Joined
Aug 20, 2013
Messages
3
Hey everybody,

I already managed to almost solve my problem with putting together a rather long formula from existing threads but when it comes to those ranges I give up.

I have a very large data set (30k rows, no blanks) and I am trying to count distinct account numbers based on two criteria but one should capture a range.

This is a simplified version:

Account Nr.CountryAge of purchase (years)
123USA1
123USA2
234USA2
234USA3
345Germany1

<tbody>
</tbody>











The question I am trying to answer is: How many clients from the USA have purchased something 1-3 years or 3-5 years ago. How many clients from Germany, etc.

I was able to figure out the formula for each individual year, but not the ranges. E.g. for year 2 I can get the distinct US clients like this:

=SUM((IF((C2:C6=2)*(B2:B6="USA")*(A2:A6<>"");1/COUNTIFS(A2:A6;A2:A6;C2:C6;2;B2:B6;"USA";A2:A6;"<>"))))

Any help is greatly appreciated!

Andi
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Something like this might help:

Excel 2010
ABC
1Account Nr.CountryAge of purchase (years)
2123USA1
3123USA2
4234USA5
5234USA3
6345Germany1
7
8
9
10
11
12
131-33-5
14USA32
15Germany10

<colgroup><col style="width: 25pxpx"><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet1

Worksheet Formulas
CellFormula
B14=COUNTIFS($B$2:$B$6,$A14,$C$2:$C$6,"<=3")
C14=COUNTIFS($B$2:$B$6,$A14,$C$2:$C$6,"<=5")-COUNTIFS($B$2:$B$6,$A14,$C$2:$C$6,"<=2")
B15=COUNTIFS($B$2:$B$6,$A15,$C$2:$C$6,"<=3")
C15=COUNTIFS($B$2:$B$6,$A15,$C$2:$C$6,"<=5")-COUNTIFS($B$2:$B$6,$A15,$C$2:$C$6,"<=2")

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>


Your criteria will result in purchases of 3 years being counted twice.
 
Upvote 0
Thanks Comfy!

However, if I understand your solution correctly, it would only count purchases but not unique clients. I meant to count the number of distinct account numbers based on the two criteria, e.g. for the range 1-5 years, there are 2 US clients (123 and 234). Is there any way to do this with your solution?

Thanks!
 
Upvote 0
Ok, so I've edited the formula which has been posted here: Formula to count unique values with criteria « Chandoo.org - Learn Excel & Charting Online - Forums

It may not be the most elegant way to do this but it seems to work.

Don't ask me how it works because I don't know, I only know enough to edit it :DD

Excel 2010
ABCDEFGH
1Account Nr.CountryAge of purchase (years)
2123USA51-33-5
3123USA1USA22
4234USA5Germany01
5234USA2
6345Germany5

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet1

Array Formulas
CellFormula
G3{=SUM(IF(FREQUENCY(IF($B$2:$B$6=$F3,IF($C$2:$C$6<4,MATCH($A$2:$A$6,$A$2:$A$6,0))),ROW($A$2:$C$6)-ROW($B$2)+1),1))}
H3{=SUM(IF(FREQUENCY(IF($B$2:$B$6=$F3,IF($C$2:$C$6<6,IF($C$2:$C$6>2,MATCH($A$2:$A$6,$A$2:$A$6,0)))),ROW($A$2:$C$6)-ROW($B$2)+1),1))}

<thead>
</thead><tbody>
</tbody>
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself

<tbody>
</tbody>
 
Upvote 0

Forum statistics

Threads
1,215,139
Messages
6,123,259
Members
449,093
Latest member
Vincent Khandagale

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