Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Calculating Averages by Date.

Calculating Averages by Date

Written by Allen Wyatt (last updated October 12, 2024)
This tip applies to Excel 97, 2000, 2002, and 2003


Suppose that you have a huge worksheet that contains all the rainfall readings for a given locale for the past hundred years or so. In cells A2:A37987 you have the dates, 1 January 1903 through 31 December 2006. In cells B2:B37987 you have the measurements for each date. Further, some of the measurements can be zero (if there is no rainfall for the day) or blank (if no reading was taken that particular day). With all this information, you want to calculate the average historic rainfall for any given day of the year.

One solution involves the use of array formulas, as detailed here:

  1. Select all the cells in column A that contain dates, and assign this range the name Dates.
  2. Select all the cells in column B that contain rainfall data, and assign this range the name Rainfall.
  3. In column D, starting in cell D2, place all the days of the year. You should end up with D2 through D366 filled with dates.
  4. In cell E2, enter the following array formula (terminate the formula by pressing Shift+Ctrl+Enter). The result of the formula is the sum of all the cells in the Rainfall range, for the date specified in cell D2.
=SUM((MONTH(Dates)=MONTH(D2))*(DAY(Dates)=DAY(D2))*Rainfall)
  • In cell F2, enter the following array formula (terminate the formula by pressing Shift+Ctrl+Enter). The result of the formula is the number of cells in the Rainfall range, for the date in cell D2, that have a value in them.
  • =SUM((MONTH(Dates)=MONTH(D2))*(DAY(Dates)=DAY(D2))*(Rainfall<>""))
    
  • In cell G2, enter the following regular formula. This is your average for the date in cell D2.
  • =IF(F2<>0,E2/F2,"")
    
  • Select the range E2:G2 and copy down for all the dates shown in column D.
  • This approach works, but it takes quite a while to calculate. This is because you effectively entered 730 array formulas, each checking over 37,000 cells. This is a lot of work, and consequently it may appear like your machine has "hung" after you complete step 7. It has not hung; it will just take it a while to complete the calculations.

    To decrease the number of calculations that must be performed, you can use a variation on the above steps. Follow steps 1 through 3, as noted, and then place the following array formula into cell E2:

    =AVERAGE(IF(ISNUMBER(Dates)*ISNUMBER(Rainfall)*(MONTH(Dates)=MONTH(D2))*(DAY(Dates)=DAY(D2)),Rainfall))
    

    You can then copy the formula down for all the dates shown in column D. The result of this formula is the actual average rainfall, the same as had been shown in column G in the previous approach.

    This formula works because of the way that Boolean arithmetic works in Excel. The ISNUMBER function returns either True or False, and the comparisons (MONTH and DAY) return either True or False. These results are all multiplied against each other, resulting in True only if all the individual tests are True. Only if they are all True will the average of the Rainfall for that particular date be calculated.

    You can reduce the calculation overhead even further by simply getting rid of all the table that calculates the averages for every day of the year. With your dates and rainfall in columns A and B, follow these steps:

    1. Select all the cells in column A that contain dates and assign this range the name Dates.
    2. Select all the cells in column B that contain rainfall data and assign this range the name Rainfall.
    3. In cell D2, place the date for which you want to check the average rainfall. (The year isn't important; only the month and day are used in the calculation.)
    4. Enter the following formula into cell E2:
    =AVERAGE(IF(ISNUMBER(Dates)*ISNUMBER(Rainfall)*(MONTH(Dates)=MONTH(D2))*(DAY(Dates)=DAY(D2)),Rainfall))
    

    That's it. Now, you can change the date in cell D2 as desired, and cell E2 will always indicate the average rainfall for that date. The formula in cell E2 is the same as the formula used in the last approach; the difference is that you aren't calculating it for all the days in a year, and thus the calculation is done much quicker.

    Another approach involves the use of Excel's filtering capabilities. Before you can use them properly, however, you must create a column that shows only the month and day for each date in your data. Use this formula in cell C2:

    =MONTH(A2) & "-" & DAY(A2)
    

    Now, turn on AutoFiltering (Data | Filter | AutoFilter) and use the drop-down list at the top of the new column to select the date for which you want an average. You then use the following formula, placed in any cell desired, to show the average rainfall for the selected date:

    =SUBTOTAL(1,B:B)
    

    ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2350) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Calculating Averages by Date.

    Author Bio

    Allen Wyatt

    With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

    MORE FROM ALLEN

    Turning Off Word's Second Guessing with Quote Marks

    When you type quote marks in a document, Word normally changes them to Smart Quotes. They look better on a printout, but ...

    Discover More

    Toggling Font Assignments in a Macro

    If you need to quickly switch a text selection from one typeface to another, one way you can do it is with a macro. This ...

    Discover More

    Inserting Summary Information

    Want to insert into your document those snippets of information that you know Word maintains about your document? It's ...

    Discover More

    Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!

    More ExcelTips (menu)

    Finding the Dates for Minimums and Maximums

    If you use Excel to maintain a collection of data, you may need to find information in one column based on information in ...

    Discover More

    Calculating Months of Tenure

    Need to know the number of months between two dates? It's easy to figure out if you use the DATEDIF function.

    Discover More

    Ages in Years and Months

    Calculating an age is a common task when working with dates. If you want to figure out the number of years and months ...

    Discover More
    Subscribe

    FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

    View most recent newsletter.

    Comments

    If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

    What is 8 + 7?

    There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


    This Site

    Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.

    Newest Tips
    Subscribe

    FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

    (Your e-mail address is not shared with anyone, ever.)

    View the most recent newsletter.