# How to Count the Number of Occurrences Between Two Dates, Categorized by Age Range

If you need to track the number of occurrences between two dates based on different age groups, Excel can help. This powerful tool allows you to easily calculate the number of events that fall within a specific age range, making it a valuable resource for tracking everything from sales leads to medical appointments. In this article, we will guide you through the process of counting occurrences by age range in Excel, step by step.

## Understanding the Problem

Before we dive into the solutions, let’s first understand the problem. Suppose we have a database of customers’ birthdates and purchase dates. We want to categorize the customers into age ranges (e.g., 18-25, 26-35, etc.) and count the number of occurrences between two dates. The challenge is to automate this process and avoid manual data entry.

## Solution 1: Using IF Function

One way to categorize age ranges is by using the IF function in Excel. First, we need to calculate the age of each customer by subtracting their birthdate from the current date. We can use the TODAY function to get the current date and the YEAR function to extract the birth year from the birthdate. Here is the formula:

``=YEAR(TODAY())-YEAR(B2)``

Assuming the birthdate is in cell B2.

Next, we can use the IF function to categorize the age ranges. Here is the formula:

``=IF(C2>=18,"18-25",IF(C2>=26,"26-35",IF(C2>=36,"36-45",IF(C2>=46,"46-55","56+"))))``

Assuming the age is in cell C2.

Finally, we can use the COUNTIFS function to count the number of occurrences between two dates. Here is the formula:

``=COUNTIFS(D:D,">="&DATE(2020,1,1),D:D,"<="&DATE(2020,12,31),E:E,"18-25")``

Assuming the purchase date is in column D and the age range is in column E. This formula will count the number of occurrences where the purchase date is between January 1, 2020, and December 31, 2020, and the age range is 18-25.

## Solution 2: Using PivotTable

Another way to categorize age ranges and count occurrences is by using a PivotTable. First, we need to create a new column that categorizes the age ranges using the IF function, as explained in Solution 1.

Next, we can create a PivotTable by selecting the data and going to Insert > PivotTable

In the PivotTable Fields pane, we can drag the age range column to the Rows area and the purchase date column to the Values area. This will create a table that shows the count of occurrences for each age range.

To filter the occurrences between two dates, we can click the drop-down arrow in the purchase date field and select Date Filters > Between. This will open a dialogue box where we can enter the start and end dates.

## Solution 3: Using Power Query

A more advanced way to categorize age ranges and count occurrences is by using Power Query. Power Query is a data transformation and cleansing tool that allows us to combine, reshape, and clean data from multiple sources.

First, we need to load the data into Power Query by going to Data > From Table/Range. In the Power Query Editor, we can add a new column that calculates the age using the same formula as in Solution 1. Next, we can use the Group By function to group the data by age range and count the occurrences. Here are the steps:

• Select the age range column.
• Go to Home > Group By.
• In the Group By dialogue box, select the purchase date column and choose the “Count Rows” option.
• Rename the new column to “Occurrences.”
• Close and load the data back to Excel.

To filter the occurrences between two dates, we can add a new step to the Power Query. Here are the steps:

• Select the purchase date column.
• Go to Home > Transform > Date Filters > Between.
• Enter the start and end dates in the dialogue box.
• Close and load the data back to Excel.

I hope this article has been helpful in guiding you through the various methods of categorizing age ranges and counting occurrences between two dates in Excel. By following the outlined steps, you can automate the process and save time and effort in managing and analyzing your data. Remember to choose the method that best suits your data and skill level and continue to explore and learn more about Excel’s functions and tools. With practice and patience, you can become proficient in data management and analysis and achieve your goals with greater efficiency.

Related: How To Count Occurrences In An Entire Workbook In Excel? ## Bibek Sapkota

I'm Bibek | Tech Enthusiast & Lifelong Learner. | Playing on the Web for the Past Few Years as an SEO Specialist and Full-Time Blogger. I'm constantly seeking out new opportunities to learn and grow, and I love sharing my knowledge with others. This is where I started this blog! Here, you will find me sharing comprehensive reviews, helpful guides, tips-tricks and ways to get the full benefits of ever-changing technology. On this blog, you can also explore Powerful Knowledge, Tips & Resources On Blogging, SEO and Passive income Opportunities.