Linked Questions

Popular Questions

Summing Consecutive Rows based on DateTime

Asked by At

I have data that looks like this...

Year   Month   Day   Hour  Total  Date       DateTime
1950   1       2     21    0.01   1/2/1950   1/2/1950 21:00
1950   1       2     23    0.01   1/2/1950   1/2/1950 23:00
1950   1       3     0     0.06   1/3/1950   1/3/1950 0:00
1950   1       3     1     0.01   1/3/1950   1/3/1950 1:00
1950   1       3     2     0.02   1/3/1950   1/3/1950 2:00
1950   1       4     11    0.24   1/4/1950   1/4/1950 11:00
1950   1       4     12    0.07   1/4/1950   1/4/1950 12:00
1950   1       4     15    0.10   1/4/1950   1/4/1950 15:00
1950   1       4     16    0.04   1/4/1950   1/4/1950 16:00
1950   1       4     17    0.01   1/4/1950   1/4/1950 17:00

and I want to sum "Total" by events or consecutive hours. For example, the first row is not consecutive with the second row, meaning they are separated by more than one hour and not continuous (look at the hour or DateTime). The first row should sum to 0.01. The second, third, fourth, and fifth observation (or rows) are continuous (not separated). All four of these observations should be summed and I want that total...and so on and so forth. I want something that looks like this...

Year    Month    Sum
1950    1         0.01
1950    1         0.10
1950    1         0.31
1950    1         0.15

which sums those consecutive hours, I do not want a daily total.

Related Questions