Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Formula to organize and count the employee's age group breakdown

0

Respected Members,

Please suggest how to organize and count the employee's respective age under the age group breakdown as given below:

Example:

Age Group Category:

20-30

30-40

40-50

50-60

Regards,

Akash Sharma

Answer
Discuss

Answers

0

Akash

You can use COUNTIFS function to group your data. To count the employees in age groups 20-30, 30-40 and 40-50 respectively, I suggest you use these in each of your yellow cells:

=COUNTIFS(B2:B53,">=20",B2:B53,"<30")

=COUNTIFS(B2:B53,">=30",B2:B53,"<40")

=COUNTIFS(B2:B53,">=40",B2:B53,"<=50")
Note that I've used >= (greater than or equal to) for the lower age and < (less than) for the upper age in each formula, except for 50 where I used <= assuming no employees fall into the 50-60 category (for some reason). This is to avoid double counting (e.g. someone aged 30).

Remember too that I gave a more developed answer to your question last November: Calculating current age of employees through using Pivot Table

Discuss
0

Please consider this formula. Enter it in F2 of your example and copy down.

=SUMPRODUCT(($B:$B>=VALUE(LEFT($E2,2)))*($B:$B<=VALUE(RIGHT($E2,2))))

The formula doesn't contain any of your criteria. These are in column E. Therefore, as you change the age limits in column E the formula supplies the corrected count. You also don't need to worry about the range because the formula takes the entire column, ignoring blanks.

Key to the solution is that in the age group 20-30, for example, the formula will count all that are both 20 or older (>=20) and 30 and younger (<=30). The way you have phrased your requirement the total of count will exceed the total of the counted. That is because those aged 30 and 40 will all be counted twice. For the 30 year olds, they will be counted in group 1 and group 2, the 40 year olds in groups 2 and 3.

Therefore you should change the groups to be 20-29, 30-39 and 40-59, avoiding everlaps. The same formula will work either way because it works with the numbers in column E. You can also fine tune the >= specs for each end of the group in the formula itself.

Discuss
0

Hi

If you have Office 365, you can use the follwing FILTER function, in F2 & copy down. This will be OK for your data, but if you have a 40 in it then the formula will be incorrect for all the formulas that have been supplied.

You need to revise your age groups IE: =<30, =<40, =<50, =<60 etc or something along those lines. The formulas supplied can then be adapted.

=COUNT(FILTER(A:B,(B:B>=LEFT(E2,2)+0)*(B:B<=RIGHT(E2,2)+0)))

John_Ru

In your last formula, it needs to be "=<50"

Discuss

Discussion

Thanks Kevin, will correct. Please note that it's better to make such comments against the Discussion attached to an Answer- that way the answerer gets a notification that something happened.
John_Ru (rep: 6142) May 6, '21 at 5:09 am
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login