简体   繁体   English

按日期计算平均值

[英]Calculate the Average By Date

In column AI have dates and in column BI have values. 在AI列中有日期,在BI列中有值。

How to calculate the average of values whose date have Month = 4 and Year = 2012? 如何计算日期为Month = 4和Year = 2012的平均值?

Seems like a good use for AverageIfs... 似乎是AverageIfs的好用法...

在此处输入图片说明

There are MANY ways to do this, but here's one way: 有很多方法可以做到这一点,但这是一种方法:

=SUMPRODUCT(B1:B4,--(MONTH(A1:A4)=4),--(YEAR(A1:A4)=2013))/SUMPRODUCT(--(MONTH(A1:A4)=4),--(YEAR(A1:A4)=2013))

Of course, change the row numbers to match your data range 当然,更改行号以匹配您的数据范围

Okay, assuming that you want to follow method one, let's use 2010 as the year base (a non-leap year). 好的,假设您要遵循方法一,让我们以2010年为基准年(非-年)。 This array formula will give you a result of 19th November: 该数组公式将为您提供11月19日的结果:

=AVERAGE(DATE(2010,MONTH(A1:A7),DAY(A1:A7)))

When you type it into the formula bar you need to complete the entry with CTRL+SHIFT+ENTER (not just the usual ENTER) so that Excel surrounds the formula with parentheses { }. 当您在公式栏中键入它时,您需要使用CTRL + SHIFT + ENTER(而不仅仅是通常的ENTER)来完成输入,以便Excel用括号{}将公式括起来。 You then need to format the cell as a date, eg. 然后,您需要将单元格格式化为日期,例如。 dd mmm. dd mmm。

If there are blank cells in the range then the above formula would give an incorrect result so it would have to be adapted as follows (made more complicated): 如果在该范围内有空白单元格,则上面的公式将给出错误的结果,因此必须进行如下修改(变得更加复杂):

=AVERAGE(IF(ISNUMBER(A1:A7),DATE(2010,MONTH(A1:A7),DAY(A1:A7))))

This is also an array formula. 这也是一个数组公式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM