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

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.

Related

Excel formula: how to sum total time between different time intervals based on a time condition

A B
Departure Date Arrival date
4/9/18 22:40 5/17/18 14:10
8/5/18 18:20 8/22/18 6:00
9/24/18 22:20 10/10/18 6:00
10/22/18 14:00 11/7/18 6:10
12/3/18 22:25 12/19/18 6:00
1/16/19 0:00 1/30/19 0:00
I need some help please. I have to calculate the total travel days for our employees for a specific period of time. I have columns A and B (all are date and time). Column A is the Departure Date, Column B is the Arrival Date.
Question: which is the Total number of travel days between:5/10/2018 and 12/10/2018?
Try this, you may need to edit it to match your needs though...
IF(AND(A4>=$A$1,B4<=$B$1),B4-A4,IF(AND(A4<=A$1,B4<=$B$1),B4-$A$1,IF(AND(A4>=A$1,B4>=$B$1),$B$1-A4)))
See:

Allocating staff to 30 minute intervals

I’m trying to create either a spreadsheet or macro that allows me to put and employee start and finish time in and then show me by each half hour how many half hours they are in.
For example;
Employee 1 - 08:30 to 10:15
The output I would want is;
08:00 0
08:30 1
09:00 1
09:30 1
10:00 0.5
10:30 0
11:00 0
So between 8:30 and 9:00 shows as one because that employee was in during that half hour. But between 10:00 and 10:30 it shows 0.5 because the employee was only in for half of that period
Then as I add more data it tells me which half hours they are covering.
I’ve tried using the ceiling and floor values, counta, countif, countifs, v and hlookups but just can’t get the desired effect.
I’m guessing it would need to be a macro.
Assuming C1 and D1 contain the start and end times of a shift and column A contains the times, use the following formula in column B:
=IF(A2>D$1,C2,IF(AND(A2>=C$1,A3<=D$1),1,MAX(0,A3-D$1)/(1/48)))
Limitations: shifts cannot cross over days, days cannot start before 00:00 or end after 23:59

Finding earliest date in excel

In one column I have to 10 times and dates (I have merged date and time in a cell). How do I find top 5 earliest dates and times? I can’t use function MIN() because I have date and time together. How should I write the function?
You need to first format your data in date/time format in Excel.
Example, the following data is entered
16/7/2018 15:00
18/7/2018 12:05
25/8/2018 11:00
13/7/2018 09:00
15/7/2018 14:00
15/7/2018 11:00
You can use the formula =small(range, rank) to find the smallest n figure. For instance, =SMALL($A$1:$A$6,1) would give the smallest (earliest) date, 13/7/2018 09:00 in this case. =SMALL($A$1:$A$6, 2) would give the second smallest (earliest) date, 15/7/2018 11:00 in this case.

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

VLOOKUP not returning for datetime

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.

Resources