简体   繁体   中英

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.

    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. 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

=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

=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.

I know which I prefer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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