VLOOKUP not returning for datetime - excel

I have a list of hours when water is used. this list does not generate hours when water was not used. I'll have list like:
Hour Liters
5/3/14 6:00 PM 36.288
5/3/14 7:00 PM 15.328
5/3/14 8:00 PM 1.6
5/4/14 11:00 PM 18.752
5/5/14 12:00 AM 21.664
5/5/14 1:00 AM 21.76
5/5/14 2:00 AM 21.76
Now I want to put them in a serial format so it should be like:
5/3/14 6:00 PM 36.288
5/3/14 7:00 PM 15.328
5/3/14 8:00 PM 1.6
5/3/14 9:00 PM 0.0
5/3/14 10:00 PM 0.0
5/3/14 11:00 PM 0.0
5/4/14 12:00 AM 21.664
5/4/14 1:00 AM 21.76
5/4/14 2:00 AM 21.76
I used VLOOKUP to retrieve for the date values and output the corresponding water used. It shows #N/A. I verified the date decimals using the match function and it gives me true.

Welcome to the world of time, base60 vs. base10 and 15 significant digit floating point precision. I find that sometimes it is simply expedient to give yourself a 'time window' to meet rather than try to round off ranges.
       
The formula in E2 is,
=SUMIFS($B$2:$B$8, $A$2:$A$8, ">"&D2-TIME(0, 0, 2), $A$2:$A$8, "<"&D2+TIME(0, 0, 2))
This give a four (±2) second window to match rather than attempting an exact match on what could be a repeating decimal. That could conceivably be tightened further but is probably fine for your hourly data. Fill down as necessary.
My column of 'serialized' times were generated using =A2 in D2 then =D2+TIME(1, 0, 0) in D3 and filled down.

Related

How to get time elapsed till 12:00 AM in same day and rest on next day

I am currently facing difficulty to calculate exact hours between In Time and Out time.
for instance :
Column A
Column B
Column C
Column D
1-1-2022
10:00 PM
1-2-2022
6:00 AM
1-2-2022
10:00 PM
1-3-2022
6:00 AM
Now, my problem is that I have to calculate the time from 10:00 PM till 12:00 AM = 2 Hours and rest to be calculated on the next day adding the previous days hours e.g. we have 6 hours from 12:00 AM till 6:00 AM for 1-2-2022 (Column C) and then 2 hours from 10:00 PM to 12:00 AM.
Looking forward your help.
You must add the date and times together, subtracting the In time from the Out time.
Slightly different method:
B2, D2 and E2 formatted as hh:mm
Then you could use mod() like so:
=MOD(D2-B2,1)

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

Excel Formula SUMIFS on date and time using date from given cell

Excel 2016 (office 365, current version)
I have a formula that works, but is manually intensive (i.e. manually edit the date in two places for each formula, and I have to do this for an entire quarter's worth of data):
=SUMIFS('Raw'!$E:$E,'Raw'!$A:$A,">=3/30/2017 0:00",'Raw'!$A:$A,"<=3/30/2017 23:00")
yields: 35.69658611 (Correct, actual sample data below)
I would like to be able to take the date value for the local sheet column M (list of dates for the month) and plug that date directly into the formula so I can copy paste the formula to calculate the rest of the month.
What I have returns a value of zero:
=SUMIFS('Raw'!$E:$E,'Raw'!$A:$A,">="&M3 &" 0:00",'Raw'!$A:$A,"<="&M3 &" 23:00")
DataTable: Raw
Date/Time value: 'Raw' column A
Data to sum: 'Raw' Column E
Both formulas are based on hint from https://www.mrexcel.com/forum/excel-questions/601474-sumifs-date-range-criteria.html
Sample data:
DateTime kW
3/30/17 23:00 0
3/30/17 22:00 0
3/30/17 21:00 0
3/30/17 20:00 0
3/30/17 19:00 0.004455278
3/30/17 18:00 0.5370675
3/30/17 17:00 2.303020833
3/30/17 16:00 4.122186389
3/30/17 15:00 5.415064722
3/30/17 14:00 6.190184167
3/30/17 13:00 3.621349167
3/30/17 12:00 3.292333056
3/30/17 11:00 4.470871944
3/30/17 10:00 2.407315556
3/30/17 9:00 2.269564167
3/30/17 8:00 1.033854722
3/30/17 7:00 0.029317778
3/30/17 6:00 0
3/30/17 5:00 0.000000556
3/30/17 4:00 0
3/30/17 3:00 0
3/30/17 2:00 0
3/30/17 1:00 0.000000278
3/30/17 0:00 0
You must remember how the date format work in Excel.
Every day since 1900/01/00 (arbitrary chosen date) are indexed.
So in short, when you type 2017/03/30 in cell M3 excel really only read "42824".
=SUMIFS('Raw'!$E:$E,'Raw'!$A:$A,">="&$M3 &" 0:00",'Raw'!$A:$A,"<="&$M3 &" 23:00")
Only change required is that you must save date in Text format (i.e, prepend an apostrophe (') to the date, thereby not allowing excel to auto-format as Date).
The final working formula was almost exactly the same as my second one, the only change really was the added $ to lock in the column on the textual concatenation:
=SUMIFS('Raw'!$E:$E,'Raw'!$A:$A,">="&$M3 &" 0:00",'Raw'!$A:$A,"<="&$M3 &" 23:00")
Only change required is that you Must save date in Text format (i.e, prepend an apostrophe (') to the date, thereby not allowing excel to auto-format as Date)
Special thanks to #MrDogme for the trigger that helped me fix the problem.

File userform listboxes with values from sheet based on cell value

VB noob. I am trying to fill userform list boxes with all times where the reservations column isn't blank, for each room. (If Reservations is blank, it's not a reservation made in advance).
Sample data:
date room intime outime Reservations
3/20/2017 5 10:00 AM 12:00 PM Group1
3/20/2017 5 1:00 PM 2:00 PM Group2
3/20/2017 3 11:00 PM 2:00 PM Group2
3/20/2017 3 1:00 PM 2:00 PM Group2
3/20/2017 4 10:25 AM
I have a listbox for each of the rooms. Here's my pseudocode:
Foreach row in range
If Reservations <>"" AND date = Date 'only want today's events
[write new statement combining intime and outtime values to display in the listbox in the userform]
Which looks like this:
So, I would like to have a userform populated when the workbook is opened to show that room 5 is booked from 10:00 AM to 12:00 AM and 1:00 PM to 2:00 PM, and that room 3 is booked from 11:00 AM to 12:00 AM and 1:00 PM to 2:00 PM.
So, a couple questions:
Would my code end up in Workbook_Open() or UserForm_Initialize()?
How do you combine the two times into one statement?
Thanks

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.

Resources