Time Length Of Subset - excel

I am using Excel 2010, and have access to PowerPivot.
I am trying to find out how to work out the time each subset lasted.
Here is an example of the data:
Run: Date: Time:
A 31/01/2018 20:00:00
A 31/01/2018 21:00:00
A 31/01/2018 22:00:00
A 31/01/2018 23:00:00
A 01/02/2018 00:00:00
A 01/02/2018 01:00:00
B 04/02/2018 10:00:00
B 04/02/2018 11:00:00
etc.
I want to find out the length of time between the first row and the last row in each different subset, so that the output will be:
Run: Time Taken:
A 05:00:00
B 01:00:00
TIA,
Teuthis

I've managed to answer the question myself, for anyone who has the same issue. Here is a picture of the solved spreadsheet, with the formula in red.
Spreadsheet inc solution
The formula is:
=(LOOKUP(A15,$A$2:$A$9,($B$2:$B$9+$C$2:$C$9)))-((INDEX($B$2:$B$9,MATCH(A15,$A$2:$A$9,0)))+INDEX($C$2:$C$9,MATCH(A15,$A$2:$A$9,0)))
=(LOOKUP(search term,array to search,(date to search in+time to search in)))-((INDEX(date to search in,MATCH(search term,array to search,0)))+INDEX(time to search in,MATCH(search term,array to search,0)))
NOTE:
You will need to make sure that the times are all in hh:mm and not dd/mm/yy hh:mm, otherwise the ones close to midnight will be incorrect.

Related

how to reference data from same point of time over last 30 days in Excel?

I have a data set of 1 minute data in Excel of last 30 days.
I am trying to compare today's value at 05:45:00 with average of last 30 days value at same time (05:45:00).
Completely stuck.
Can anyone help: Dataset looks like this:
Time Value
05:30:00 11.00
05:31:00 6.00
05:32:00 20.00
05:33:00 50.00
05:34:00 69.00
05:35:00 31.00
05:36:00 90.00
05:37:00 56.00
05:38:00 26.00
05:39:00 24.00
05:40:00 22.00
05:41:00 71.00
05:42:00 80.00
05:43:00 85.00
05:44:00 41.00
**05:45:00 44.00**
05:46:00 28.00
05:47:00 43.00
I did try to convert days in to minutes by doing
=(last day - first day)*1440
after that I am completely stuck what needs to be done. Not very proficient with Excel.
Are you aware how datetime works in Excel?
It is based on the value "1" being equal to one day.
So, the hour-value "05:30" equals "=5.5/24" as you can see from this screenshot:
So, If you want to add 30 days to a timestamp, just add the value 30.

Excel remove timestamp from date and subtract days

So I have a column say Date1 which has date in datetime stamp. I want to subtract 10 days from Date1 column and keep in another column say Date2. I only want to subtract ten days from date not from datetime.
How to remove the time stamp. Read many solutions online but could not find for excel
Input table
Date1
26-03-2000 21:00:00
25-04-2000 00:00:00
21-03-2000 01:00:00
31-03-2000 13:00:00
05-03-2012 12:00:00
Expected output
Date1 Date2 Date1_no_timestamp
26-03-2000 21:00:00 16-03-2000 26-03-2000
25-04-2000 00:00:00 15-04-2000 25-04-2000
21-03-2000 01:00:00 11-03-2000 21-03-2000
31-03-2000 13:00:00 21-03-2000 31-03-2000
05-03-2012 12:00:00 24-02-2012 05-03-2012 and so on
You could use the TEXT() function.
=TEXT(B2, "DD-MM-YYYY")
Alternatively, as the above solution could cause issue based on timezone formatting, you could remove anything past the first space:
=LEFT(B2, FIND(" ",A2,1)-1)
Place either the following in C2 (assuming those headers exist) and drag down.
You could use:
Method 1:
Date1_no_timestamp:
=TEXT(A2,"dd-mm-yyyy")
Date2:
=TEXT(A2-10,"dd-mm-yyyy")
Method 2
Date1_no_timestamp:
=RIGHT("0"&DAY(A2),2)&"-"&RIGHT("0"&MONTH(A2),2) & "-" & YEAR(A2)
Date2:
=TEXT(DATEVALUE(E2)-10,"dd-mm-yyyy")
Results:
You can also use the INT() and TRUNC() functions:
=INT(A2)
=TRUNC(A2)
Their behavior is identical for positive numbers - the decimal part is sliced off.

Excel Date-Time Formula

I need to fill in dates corresponding to time. I just need something that increments the date when the time changes from 23 to 0. Here is what my sheet looks like:
5/1/2017 23:00
5/1/2017 23:00
5/1/2017 23:00
? 0:00
? 0:00
? 0:00
I've tried these with different formats for the time column:
IF(AND(B4=0,B3=23),A3+1,A3)
IF(AND(B4="1/0/1900 12:00:00 AM",B3="1/0/1900 11:00:00 PM"),A3+1,A3)
IF(AND(B4="12:00:00 AM",B3="11:00:00 PM"),A3+1,A3)
Your first formula looks correct but you can see where it's wrong if you type =B3=23 into a cell (it's FALSE). Instead, try B3=23/24: =IF(AND(B4=0,B3=23/24),A3+1,A3).
A B
1 5/1/2017 11:00:00 PM
2 XXX 12:00:00 AM
Where XXX is = IF(ABS(B1-23/24)<0.001,IF(ABS(B2-24/24)<0.001,A1+1,A1),A1)
what we do here is a nested if statement, basically saying if A and B
where A is "time in cell above is near 11 pm"
and B is "time in cell is near zero"
the way date/times work in excel is that the fractional portion corresponds to time after midnight. So 1/24 ~ .041667 is an hour past midnight, and 23/24 is 11 pm

Average column by specific datetime associated values

I have one column with the time in format "dd/mm/yyyy hh:mm" and another with the temperature for that time point. I am looking to calculate the average temperature of the day and night of each month separately. I.e. average all temperatures between 06:00 and 18:00 in May and all temperature between 18:00 and 06:00 in May and then the same for March and so on.
Time Celsius(C)
06/05/2016 10:49 28
06/05/2016 11:49 29
06/05/2016 12:49 31
06/05/2016 13:49 27.5
06/05/2016 14:49 24
06/05/2016 15:49 25
06/05/2016 16:49 24.5
06/05/2016 17:49 23.5
06/05/2016 18:49 23
06/05/2016 19:49 22.5
06/05/2016 20:49 22.5
I am currently using the following formula:
=AVERAGEIFS(C2:C3643,B2:B3643,">=01/05/2016",B2:B3643,"<=31/05/2016",B2:B3643,">=01/05/2016 06:00",B2:B3643,"<=31/05/2016 18:00")
To try and calculate an average if the date is within May and during the day - however it doesn't appear to be working and when I change the hour periods it still spits out the same number (which is the average for the month).
You can use a long SUMPRODUCT Formula:
For the 600 to 1800 in May:
=SUMPRODUCT(($A$2:$A$12>=DATE(2016,5,1))*($A$2:$A$12<=DATE(2016,5,31))*(MOD($A$2:$A$12,1)>=TIME(6,0,0))*(MOD($A$2:$A$12,1)<=TIME(18,0,0))*B2:B12)/SUMPRODUCT(($A$2:$A$12>=DATE(2016,5,1))*($A$2:$A$12<=DATE(2016,5,31))*(MOD($A$2:$A$12,1)>=TIME(6,0,0))*(MOD($A$2:$A$12,1)<=TIME(18,0,0)))
You can always replace all the DATE() and TIME() parts with cell references instead of hard coding them.
To get the between 1800 and 600 we need to shift it to an OR with + between the Time Boolean instead of *:
=SUMPRODUCT(($A$2:$A$12>=DATE(2016,5,1))*($A$2:$A$12<=DATE(2016,5,31))*((MOD($A$2:$A$12,1)<=TIME(6,0,0))+(MOD($A$2:$A$12,1)>=TIME(18,0,0)))*B2:B12)/SUMPRODUCT(($A$2:$A$12>=DATE(2016,5,1))*($A$2:$A$12<=DATE(2016,5,31))*((MOD($A$2:$A$12,1)<=TIME(6,0,0))+(MOD($A$2:$A$12,1)>=TIME(18,0,0))))
This relies on you creating a table of months and time ranges like below:
Enter this formula in E2 and drag around as needed. It's an array formula, so must be entered with Ctrl-Shift-Enter:
=AVERAGE(IF(
((MONTH($A$2:$A$101)=MONTH(E$1&1))*
((MOD(HOUR($A$2:$A$101)-LEFT($D2,2),24))>=0)*
((MOD(HOUR($A$2:$A$101)-LEFT($D2,2),24))<12)),
$B$2:$B$101))
Notes:
The MONTH(E$1&1) part lets you get a month number from text like
"Jan"
I used MOD and subtraction of the left part of the time range to get
the target hour in a range from 0 to 23. This made it possible to filter on values between 1 and 11.
If Barry Houdini were still around he could do it in half the space, I'm sure.
While working with datetime and when the actual day is reckoned beyond midnight like in 18 hrs to 6 hrs the next day, I find it useful to offset the time back and do the calculations.
6:00 to 18:00 =AVERAGE(IF((MONTH($A$2:$A$12-0.25)=D2)*(MOD($A$2:$A$12-0.25,1)<0.5),$B$2:$B$12,""))
18:00 to 6:00 =AVERAGE(IF((MONTH($A$2:$A$12-0.25)=D2)*(MOD($A$2:$A$12-0.25,1)>=0.5),$B$2:$B$12,""))
These are array formulas entered with Ctrl-Shift-Enter.
Here I am offsetting time by 0.25 days which is 6 hours.

How to add a column with the corresponding day?

I want to create data that ranges from 01/01/2004 00:30:00 to 31/12/2004 23:30:00 with time step half hourly. I would like also to add a column with just the corresponding day using excel for example:
01/01/2004 00:30:00 1
01/01/2004 01:00:00 1
01/02/2004 00:30:00 2
31/12/2004 23:30:00 365
I tried to make it but I wonder why from cretin date the time step was changing from:
03/01/2004 **01:30**
03/01/2004 **02:00**
to
03/01/2004 **02:29**
03/01/2004 **02:59**
03/01/2004 03:29
03/01/2004 03:59
Any help?
Assuming your date is in cell A1, the following formula will work:
=INT(A1)-DATE(YEAR(A1),1,0)
The Int removes the time from the date, and then it subtracts December 31st of the previous year to produce the number of days that have passed in the year.
For the step, use formula
=A1+1/48 and copy down.

Resources