Written by Allen Wyatt (last updated September 3, 2020)
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:
=SUM((MONTH(Dates)=MONTH(D2))*(DAY(Dates)=DAY(D2))*Rainfall)
=SUM((MONTH(Dates)=MONTH(D2))*(DAY(Dates)=DAY(D2))*(Rainfall<>""))
=IF(F2<>0,E2/F2,"")
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:
=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.
Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!
Excel allows you to perform all sorts of calculations using dates. A good example of this is using a formula to figure ...
Discover MoreExcel can easily store dates. If you want to increment a date by one month, there are a number of ways you can accomplish ...
Discover MoreThose in Europe use a date format that is different than those in the US; this is not news. But what if you need to ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2022-03-14 12:09:17
John
This was really useful, thank you.
2021-01-21 10:19:04
Rajbardhan
Hi ,
Please help me ..Need Average for 7 days from Particular dates in Column ..
Pre Date Post Date KPI 1-Dec 2-Dec 3-Dec 4-Dec 5-Dec 6-Dec 7-Dec 8-Dec 9-Dec 10-Dec 11-Dec 12-Dec 13-Dec 14-Dec
7-Dec 28-Dec Data-1 470.6 494.5 501.8 511.3 522.3 513.2 469.8 519.3 496.9 476.2 458.8 468.7 474.7 457.9
7-Dec 28-Dec Data-2 58.65 58.76 59.34 55.27 82.42 74.35 62.82 81.24 65.8 64.99 64.25 66.14 70.08 68.08
7-Dec 28-Dec Data-3 411.96 435.78 442.5 456.03 439.86 438.83 406.93 438.04 431.09 411.17 394.51 402.56 404.61 389.78
7-Dec 28-Dec Data-4 794.8 773.8 809.3 809.6 711.1 833.4 767.9 825.1 811.0 744.1 725.6 751.3 844.6 707.9
In Above sheet, i need Pre Date as Starting point and than same from 7th December in Column for next 7days Average ( 7 Dec to 13 Dec) Data.
2016-11-07 07:12:46
Elisha
I have one column with dates, and another column with numbers. I want to reduce the rows such that for each similar date, I have an average of the numbers.
1-Jan-50 -9999
1-Jan-50 2
2-Jan-50 -9999
2-Jan-50 5
3-Jan-50 -9999
3-Jan-50 0.2
How do I go about it?
2016-02-08 14:18:16
Rick
A very useful way to look at sales data for months or quarters, also. However, my version of Excel 2000 returns a value of 1 for MONTH(A2) if cell A2 is blank. I had to verify the cell is not blank with an if statement for spotty data at the beginning of my worksheet.
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.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2023 Sharon Parq Associates, Inc.
Comments