简体   繁体   English

Excel困难应该很容易,用列中的日期时间计算两个不丢失条目之间的平均值

[英]Excel difficult should be easy, calculate average between two non-missing entries with date-time in a column

I have to calculate average consumption for corresponding time frames (while table also contains other data). 我必须计算相应时间范围内的平均消耗量(而表还包含其他数据)。 I have a table with date and time columns (european format) and a column with occasional counter state (fetched from text column with =IF(ISNUMBER(SEARCH("count.state.";E1));MID(E1;FIND("count.state.";E1)+12;5);""). I would like to calculate average consumption automatically instead of having to manually select ranges, edit formula, then copy etc. 我有一个带有日期和时间列(欧洲格式)的表,以及一个带有偶尔计数器状态的表(从带有= IF(ISNUMBER(SEARCH(“ count.state。”; E1))的文本列中获取); MID(E1; FIND( “ count.state。”; E1)+12; 5);“”)。我想自动计算平均消耗量,而不必手动选择范围,编辑公式然后复制等。

    A       B       F       G
1   2.12.   23:00   10765   =INDEX/MATCH formula should use the same data as 3 rows below 
2   3.12.   8:00    ""      =INDEX/MATCH formula should use the same data as 2 rows below 
3   3.12.   11:00   ""      =INDEX/MATCH formula should use the same data as in the row below 
4   3.12.   18:00   10769   =(10769 - 10765) / (3.12.18:00 - 2.12.23:00)
5   3.12.   23:00   ""      =INDEX/MATCH formula should use the same data as 5 rows below 
6   4.12.   11:00   ""      =INDEX/MATCH formula should use the same data as 4 rows below 
7   4.12.   15:00   ""      =INDEX/MATCH formula should use the same data as 3 rows below 
8   4.12.   18:00   ""      =INDEX/MATCH formula should use the same data as 2 rows below 
9   4.12.   23:00   ""      =INDEX/MATCH formula should use the same data as in the row below 
10  5.12.   18:00   10786   =(10786 - 10769) / (5.12.18:00 - 3.12.23:00)

I am learning to use Excel functions but this seems to be way way over my head. 我正在学习使用Excel函数,但这似乎有点麻烦。 Anyone has a solution to this challenge? 任何人都可以解决这个挑战吗? Thanks for your patience and effort. 多谢您的耐心与努力。

Miki 三木

Well OK maybe not the elegant solution you're looking for but it gets the job done. 好吧,也许不是您要找的优雅解决方案,但它可以完成工作。

The idea is just to use helper columns to copy the date/time and counter reading from the row containing the last counter reading down through all the rows up to the one before the next counter reading like this 这样的想法只是使用帮助器列从包含最后一个计数器的行中复制日期/时间和计数器读数,直到所有下一行都向下读到下一个计数器读数为止,像这样

=IF(ISNUMBER(F2),F2,H1) for the counter starting in H2

=IF(ISNUMBER(F2),G2,I1) for the date/time starting in I2

then when you get to the row containing the next counter reading, do the calculation. 然后,当您到达包含下一个计数器读数的行时,进行计算。

My column G contains the date & time put together using 我的G栏包含使用

=DATEVALUE(A2&"2014")+B2 starting in G2.

I have taken the liberty of changing the dots in the dates to slashes because of my locale. 由于我的语言环境,我自由地将日期中的点更改为斜线。

Then the actual calculation is 那么实际的计算是

=IF(AND(ISNUMBER(F2),ISNUMBER(I1)),(H2-H1)/(I2-I1),"")

To copy the result back through each time period I have started at the bottom in cell K11 and pulled the formula upwards 为了将结果复制回每个时间段,我从单元格K11的底部开始并将公式向上拉

=IF(ISNUMBER(J11),J11,K12)

It looks like this 看起来像这样

在此处输入图片说明

However there is a useful discussion of finding the first and last cell with a numerical entry here which leads to the formula 然而,有发现有数字输入的第一个和最后一个单元格的一个有用的讨论在这里这导致了公式

=IFERROR((INDEX(F2:F$11,MATCH(1,INDEX(ISNUMBER(F2:F$11)+0,0),0))-(INDEX(F$1:F1,MATCH(9E+307,F$1:F1,1))))/(INDEX(G2:G$11,MATCH(1,INDEX(ISNUMBER($F2:F$11)+0,0),0))-(INDEX(G$1:G1,MATCH(9E+307,F$1:F1,1)))),"")

to be placed in H2 and pulled down and is a direct way of finding the answers. 将其放置在H2中并下拉,是找到答案的直接方法。

I know which I prefer. 我知道我更喜欢哪个。

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

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