Formula to calculate age ranges

mnoah

Board Regular
Joined
Oct 14, 2015
Messages
54
Hello,

Looking to calculate age ranges of people in an excel list, but it should only count the non-duplicated names. So for the example below, it should only count "Same Person" and "Other Same Person" once so that it does not give me a false record of people in that age range.

I would like to accomplish this with a formula and not a pivot table, and no helping columns/calculations. I've tried using some variations of sumproduct and countif, but to no avail.

NameAgeAge RangeCount
Same Person7520-303
Other Same Person2031-400
Same Person7541-502
Same Person7551-600
John Doe5061+1
Elaine Smith23
Wendy Troupe50
Levi Smith25
Other Same Person20

<tbody>
</tbody>
 
Last edited:

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Based on your sample, try this, copied down...
=COUNTIFS($B$2:$B$10,">="&--LEFT(D2,2),$B$2:$B$10,"<="&IF(ISNUMBER(FIND("+",D2)),150,--RIGHT(D2,2)))
 
Upvote 0
Based on your sample, try this, copied down...
=COUNTIFS($B$2:$B$10,">="&--LEFT(D2,2),$B$2:$B$10,"<="&IF(ISNUMBER(FIND("+",D2)),150,--RIGHT(D2,2)))

Thank you for taking the time! But unfortunately, this count's the duplicated people's ages. The count for age range 61+ should only be 1, since "Same Person" should not be counted three times.

For example, I use this code to do something similar. It finds unduplicated counts of gender based on non-duplicated names in column B

Code:
=SUMPRODUCT((I2:I800="Male")/COUNTIF(B2:B800,B2:B800&""))
 
Last edited:
Upvote 0
Think I figured it out, but can anyone help me out a bit? Would like to add the red part highlighted below.

BTW, this is an array:

Code:
=SUM((B2:B800>=61 [COLOR=#ff0000]BUT LESS THAN 75??[/COLOR])/COUNTIF(A2:A800,A2:A800&""))
 
Upvote 0
Maybe something like this.
These are array formulas and must be entered with CTRL-SHIFT-ENTER (command-return on MAC).

In this example formula in E2 can be copied down to E5. Formula in E6 is different since no upper limit.
Excel Workbook
ABCDE
1NameAgeAge RangeCount
2Same Person7520-303
3Other Same Person2031-400
4Same Person7541-502
5Same Person7551-600
6John Doe5061+1
7Elaine Smith23
8Wendy Troupe50
9Levi Smith25
10Other Same Person20
Sheet
 
Upvote 0
Thank you for taking the time! But unfortunately, this count's the duplicated people's ages. The count for age range 61+ should only be 1, since "Same Person" should not be counted three times.

For example, I use this code to do something similar. It finds unduplicated counts of gender based on non-duplicated names in column B

Code:
=SUMPRODUCT((I2:I800="Male")/COUNTIF(B2:B800,B2:B800&""))

It's faster to use the FREQUENCY formula... Control+shift+enter, not just enter:
Rich (BB code):
=SUM(IF(FREQUENCY(IF(1-($B$2:$B$800=""),IF($I$2:$I$800="Male",
    MATCH($B$2:$B$800,$B$2:$B$800,0))),ROW($B$2:$B$800)-ROW($B$2)+1),1))

Also, why not set up the age range in a 2-column representation for faster calculations?

Row\Col
A​
B​
C​
D​
E​
F​
1​
Name Age Age Range (from) to Count
2​
Same Person 75 20 30
3​
3​
Other Same Person 20 31 40
0​
4​
Same Person 75 41 50
2​
5​
Same Person 75 51 60
0​
6​
John Doe 50 61 1.00E+308
1​
7​
Elaine Smith 23
8​
Wendy Troupe 50
9​
Levi Smith 25
10​
Other Same Person 20

E6 contains: 9.99999999999999E+307, which is a useful Excel contant.

In F2 control+shift+enter, not just enter, and copy down:
Rich (BB code):
=SUM(IF(FREQUENCY(IF(1-($A$2:$A$10=""),IF($B$2:$B$10>=$D2,
    IF($B$2:$B$10<=$E2,MATCH($A$2:$A$10,$A$2:$A$10,0)))),
   ROW($A$2:$A$10)-ROW($A$2)+1),1))
 
Upvote 0
oops missed the unique bit...
=SUM(--(FREQUENCY(IF((($B$2:$B$10>=--LEFT(D2,2))*($B$2:$B$10<=IF(ISNUMBER(FIND("+",D2)),160,--RIGHT(D2,2)))),$B$2:$B$10),$B$2:$B$10)>0))
ARRAY formula, using CTRL SHIFT ENTER, not just enter, then copied down
 
Upvote 0
You're welcome. I do agree with Aladin it would be better if you could split your age range into 2 columns which would eliminate the need for the LEFT and RIGHT functions.
Thanks for the feedback.
 
Upvote 0
You're welcome. I do agree with Aladin it would be better if you could split your age range into 2 columns which would eliminate the need for the LEFT and RIGHT functions.
Thanks for the feedback.

Agreed, because then you could do away with the LEFT() and RIGHT functions in my suggestion too
 
Upvote 0

Forum statistics

Threads
1,215,465
Messages
6,124,975
Members
449,200
Latest member
Jamil ahmed

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