where data is an Excel Table in the range (C5:B16). As the formula is copied down, it returns a count of birthdays per year as shown. Video: What is an Excel table. Note: this example has been updated below to show how to create an all-in-one formula with dynamic arrays in the latest version of Excel.


The easiest way to solve this problem is to use the SUMPRODUCT function together with the YEAR function like this in cell F5: Working from the inside out, we use the YEAR function to extract the year from each birthday: Because there are 12 dates in the list, the YEAR function returns 12 values in an array like this: Next, each value in this array is compared against the year in E5, which is 1999. The result is a new array containing only TRUE and FALSE values: In this array, TRUE represents birth years equal to 1999 and FALSE represents birth years not equal to 1999. We want to count the TRUE values, but because SUMPRODUCT will ignore the logical values TRUE and FALSE, we need to convert these values to 1s and 0s first. To perform this conversion, we use a double negative (–). The result is an array that contains just 1s and 0s, which is returned directly to the SUMPRODUCT function like this: With only one array to process, SUMPRODUCT sums the array and returns a result of 3 in cell F5. As the formula is copied down, it returns a count of birthdays per year as seen in the worksheet. Note: The SUMPRODUCT formula above is an example of using Boolean logic in an array operation. This is a powerful and flexible approach to solving many problems in Excel. It is also an important skill with new functions like FILTER and XLOOKUP, which often use this technique to apply multiple criteria (FILTER example, XLOOKUP example)

COUNTIFS function

The COUNTIFS function can also be used to solve this problem but the formula is more complicated, because COUNTIF only works with ranges, and you can’t extract the years to use as the range argument inside COUNTIFS. Instead, you must create a start and end date for each year. The formula looks like this: In a nutshell, we create a first-of-year date (1-Jan-1999) and an end-of-year date (31-Jan-1999) using the year in E5 with the DATE function: The DATE function creates Excel dates with separate year, month, and day arguments. In the example, month and day are hard-coded, and we get year from column E. These dates are concatenated to the greater than or equals to operator (>=) to make criteria1, and the less than or equals to operator (<=) to make criteria2. The range for both criteria is data[Birthday]. Notice the operators must be enclosed in double quotes (""). As the formula is copied down column F, it returns a count of birthdays per year, same as the SUMPRODUCT formula.

Dynamic array solution

In the latest version of Excel, which supports dynamic array formulas, it is possible to create a single all-in-one formula that builds the entire summary table, including headers, like this: The LET function is used to assign three intermediate variables: years, uyears, and counts. The value for years is created like this: Here, the YEAR function is used to extract just the year from all dates in data[Birthday]. Because the table contains 12 rows, the result is an array with 12 year values like this: Next, the value for uyears (unique years) is created like this: Out of 12 year values, the UNIQUE function returns just 4 unique years: This array is returned to the SORT function, which returns an array sorted in ascending order: In this example, it happens that the unique years are already in ascending order, so the SORT function does not change the result from UNIQUE. However, using the SORT function ensures that year values will always appear in order when source data is not sorted. Next, the BYROW function is used to create a value for counts for each year like this: BYROW runs through the uyears values row by row. At each row, it applies this calculation: The value for r is the year in the “current” row. Inside the SUM function, this value is compared to years. Since years contains all 12 years, the result is an array with 12 TRUE and FALSE results. The TRUE and FALSE values are converted to 1s and 0s with the double negative (–), and the SUM function simply adds up the result, which is the count of birthdays associated with the current row. Since there are 4 unique years, the result from BYROW is an array with 4 counts like this: Finally the HSTACK and VSTACK functions are used to assemble a complete table: At the top of the table, the array constant {“Year”,“Count”} creates a header row. The HSTACK function combines uyears and counts horizontally, and VSTACK combines the header row and the data to make the final table. The result spills into multiple cells on the worksheet:

Pivot table solution

A Pivot Table is a good solution for this problem as well. This example shows how to count birthdays by month with a Pivot Table.

Dave Bruns

Hi - I’m Dave Bruns, and I run Exceljet with my wife, Lisa. Our goal is to help you work faster in Excel. We create short videos, and clear examples of formulas, functions, pivot tables, conditional formatting, and charts.