How to sum values in Excel that occur between 2 hours - excel

I would like to sum the sales depending on the time diapasons of the day-night in which they occur. For example, I would like to sum all sales that happened between 22:00h and 2:00h.
Hour Sales
18:58 49
18:00 49.5
03:01 31
20:00 139
09:15 61.5
11:36 5
08:00 24
16:32 25
12:30 96.5
17:30 75.5
09:00 80
00:10 24
15:00 24
18:00 216
09:30 24
06:30 47.5
So if I try to do a sumifs where the hour is >=22:00 and <23:00, the formula works. However, if I try to sumifs the values between 22:00 and 2:00, in other words the first criteria is ">=22:00" and the second is "<2:00", the sumifs cannot work. I do understand why but I'm struggling to find an alternative way to solve this task.

As stated, we need to add 1 when it rolls to the next day, which means SUMPRODUCT:
=SUMPRODUCT($B$2:$B$17,((E2<D2)+$A$2:$A$17>=D2)*(($A$2:$A$17<D2)+$A$2:$A$17<(E2<D2)+E2))

Related

formula to calculate work hours and sort by employee in an overlapping data array

I have a .XLXS table with worker names, start times, and end times. I want to show the total hours worked by worker while ignoring overlapping periods.
For example if "Bob" works from 0800 to 1400 and also works from 0900 to 1300 his total time for that day should be 6 hours. If "Joe" works 0700 to 0900 his time for that day is 2 hours.
The number of workers varies and six months of data is about 2100 rows.
The formula provided by "barry houdini" to "Formula that will calculate total hours in overlapping date array" works for one worker but I don't know enough about Excel to make it sort for multiple workers.
=SUMPRODUCT((COUNTIFS(B:B,"<"&MIN(B:B)+ROW(INDIRECT("1:"&ROUND((MAX(C:C)-MIN(B:B))*1440,0)))/1440-1/2880,C:C,">"&MIN(B:B)+ROW(INDIRECT("1:"&ROUND((MAX(C:C)-MIN(B:B))*1440,0)))/1440-1/2880)>0)+0)/60
MOD_BY START_DATETIME END_DATETIME total time
bob 1/2/19 17:30 1/2/19 18:45 3.2500
bob 1/2/19 21:00 1/2/19 21:15
bob 1/2/19 21:00 1/2/19 22:00
bob 1/2/19 15:00 1/2/2019 16:00
joe 1/2/19 17:30 1/2/19 18:45
joe 1/2/19 21:00 1/2/19 21:15
joe 1/2/19 21:00 1/2/19 22:00
joe 1/2/19 15:00 1/2/2019 16:00
My objective is to have an output of total hours worked by worker. The formula as provided gives a total for the entire file without breaking it down by worker.
You will need MAXIFS and MINIFS which means you need Office 365 Excel:
=SUMPRODUCT(--(COUNTIFS(A:A,"bob",B:B,"<=" & MINIFS(B:B,A:A,"bob") + ROW($XFD$1:INDEX($XFD:$XFD,ROUND((MAXIFS(C:C,A:A,"bob")-MINIFS(B:B,A:A,"bob"))*1440,0)))/1440-1/2880,C:C,">=" & MINIFS(B:B,A:A,"bob") + ROW($XFD$1:INDEX($XFD:$XFD,ROUND((MAXIFS(C:C,A:A,"bob")-MINIFS(B:B,A:A,"bob"))*1440,0)))/1440-1/2880)>0))/60

Adjust given date range and interpolate values

Good afternoon,
I have a data set, which contains reporting dates and various parameters corresponding with this date. Each parameter provides a value related to the duration between the reports. So, the set contains multiple rows with the same date (but different time), and could contain a single row for which values are applicable to multiple dates.
Example of the set listed below:
Date Distance Price
02-01-2018 04:00 370 26.71
03-01-2018 04:00 357 27.31
04-01-2018 04:00 376 23.47
04-01-2018 04:48 8 0.72
04-01-2018 05:36 0 0.19
05-01-2018 04:00 328 23.77
05-01-2018 17:30 202 15.23
07-01-2018 17:13 7 1.54
08-01-2018 05:00 0 7.44
09-01-2018 05:00 0 3.89
10-01-2018 04:00 333 21.38
10-01-2018 11:00 110 6.40
What i would like to get:
Date Distance covered Price
02-01-2018 04:00 370 26.71
03-01-2018 04:00 357 27.31
04-01-2018 04:00 376 23.47
05-01-2018 04:00 336 24.67
06-01-2018 04:00 204 15.56
07-01-2018 04:00 4 0.77
08-01-2018 04:00 2 7.24
09-01-2018 04:00 0 3.93
10-01-2018 04:00 333 21.55
11-01-2018 04:00 110 6.40
I want to be able to choose a start date/time, and create a macro which automatically creates 24hr intervals after this date till the end of data set and interpolates the parameters.
Any help would be much appreciated. Thanks in advance.
Best regards,

Filling in time gaps in Excel

I have the following in excel sheet:
start end value
1 26/11/2014 13:00 26/11/2014 20:00 decreasing
2 26/11/2014 20:00 27/11/2014 09:00 increasing
I would like to transfer the above table to a table in which each row time is opened and filled in with the value. The time gap is filled in from the start time to the end time - 1, as followed:
date hour value
1 26/11/2014 13:00 decreasing
2 26/11/2014 14:00 decreasing
3 26/11/2014 15:00 decreasing
4 26/11/2014 16:00 decreasing
5 26/11/2014 17:00 decreasing
6 26/11/2014 18:00 decreasing
7 26/11/2014 19:00 decreasing
8 26/11/2014 20:00 increasing
9 26/11/2014 21:00 increasing
10 26/11/2014 22:00 increasing
11 26/11/2014 23:00 increasing
12 26/11/2014 00:00 increasing
13 26/11/2014 01:00 increasing
14 26/11/2014 02:00 increasing
15 26/11/2014 03:00 increasing
16 26/11/2014 04:00 increasing
17 26/11/2014 05:00 increasing
18 26/11/2014 06:00 increasing
19 26/11/2014 07:00 increasing
20 26/11/2014 08:00 increasing
Assuming this is the location of your original data :
B2 ---> 26/11/2014 13:00
B3 ---> 26/11/2014 20:00
C2 ---> 26/11/2014 20:00
C3 ---> 27/11/2014 09:00
D2 ---> decreasing
D3 ---> increasing
And in sheet2, put some labels :
B1 ---> date
C1 ---> hour
D1 ---> value
Some date generator.. Assuming Sheet1!B2 is the start date..
B2 ---> =DATE(YEAR(Sheet1!B2),MONTH(Sheet1!B2),DAY(Sheet1!B2))
C2 ---> =TIME(HOUR(Sheet1!B2),MINUTE(Sheet1!B2),SECOND(Sheet1!B2))
B3 ---> =IF(INT((C2+TIME(1,0,0)))>INT(C2),B2+1,B2)
C3 ---> =IF((TIME(HOUR(C2),MINUTE(C2),SECOND(C2))+TIME(1,0,0))>1,TIME(HOUR(C2),MINUTE(C2),SECOND(C2))+TIME(1,0,0)-1,TIME(HOUR(C2),MINUTE(C2),SECOND(C2))+TIME(1,0,0))
and lastly, using and Sheet1!C3 as the end date, define output.
D2 ---> =IF((B2+IF(C2=1,0,C2))<Sheet1!$C$3,IF((B2+IF(C2=1,0,C2))<Sheet1!$C$2,Sheet1!$D$2,Sheet1!$D$3),"")
drag the until E21. Done.
I hope that'll help. Do buzz me if there is any part of the formula that you can't understand. ( :

Index/Match Time Match Errors

I am using index/match to extract data by matching date/times using INDEX(D:D,MATCH(A2,B:B,0))
A:A column of date/times has been manually entered.
B:B column of date/times input as B2+time(,30,) and copied down.
After 3 lines the formula gives #N/A as an answer.
It has something to do with the times not matching exactly even though A5=B5 gives a true result that row gives #N/A
If I copy A:A to B:B i.e. all manually entered times it works perfectly.
Please help.
A B C D E F G H I J K
AET Entered AET + 30 = volts lo i1 i0 vl1 vl0 Value AET Value Time +30
1/08/15 10:00 1/08/15 10:00 TRUE 36 36 36 36 36 36 42217.4166666667000 42217.4166666667000
1/08/15 10:30 1/08/15 10:30 TRUE 23 23 23 23 23 23 42217.4375000000000 42217.4375000000000
1/08/15 11:00 1/08/15 11:00 TRUE 44 44 44 44 44 44 42217.4583333333000 42217.4583333333000
1/08/15 11:30 1/08/15 11:30 TRUE 55 44 44 #N/A 44 #N/A 42217.4791666667000 42217.4791666667000
1/08/15 12:00 1/08/15 12:00 TRUE 13 55 55 #N/A 55 #N/A 42217.5000000000000 42217.5000000000000
1/08/15 12:30 1/08/15 12:30 TRUE 32 13 13 #N/A 13 #N/A 42217.5208333333000 42217.5208333333000
1/08/15 13:00 1/08/15 13:00 TRUE 56 32 32 #N/A 32 #N/A 42217.5416666667000 42217.5416666667000
1/08/15 13:30 1/08/15 13:30 TRUE 70 56 56 #N/A 56 #N/A 42217.5625000000000 42217.5625000000000
1/08/15 14:00 1/08/15 14:00 FALSE 43 70 70 #N/A 70 #N/A 42217.5833333333000 42217.5833333334000
1/08/15 14:30 1/08/15 14:30 TRUE 31 43 43 #N/A 43 #N/A 42217.6041666667000 42217.6041666667000
1/08/15 15:00 1/08/15 15:00 TRUE 21 31 31 #N/A 31 #N/A 42217.6250000000000 42217.6250000000000
1/08/15 15:30 1/08/15 15:30 FALSE 11 21 21 #N/A 21 #N/A 42217.6458333333000 42217.6458333334000
1/08/15 16:00 1/08/15 16:00 TRUE 66 11 11 #N/A 11 #N/A 42217.6666666667000 42217.6666666667000
1/08/15 16:30 1/08/15 16:30 TRUE 45 66 66 #N/A 66 #N/A 42217.6875000000000 42217.6875000000000
1/08/15 17:00 1/08/15 17:00 FALSE 23 45 45 #N/A 45 #N/A 42217.7083333333000 42217.7083333334000
I'll leave #AxelRichter to post the answer in his comment, which involves rounding the timestamps and referencing the rounded numbers to avoid floating point precision.
An alternative solution would be to simply allow VLOOKUP/MATCH to pick up the 'nearest value' result, using the final argument in each function. ie:
=INDEX(D:D,MATCH(A2,B:B,1))
Keep in mind that this will only work if your data is sorted. It has the added benefit that if a missing result should naturally be the next closest row, that row is picked up - and likewise it has the added cost that it will not warn you when a match isnt found.
This is an issue with floating point precision. As you see even the = comparison fails with 1/8/15 14:00 42012,5833333333 vs. 42012,5833333334. The exact matching with MATCH(..,0) or VLOOKUP(.., FALSE) uses an other comparison method and so it fails more often. If we need exact matching date time values then we need those values ROUNDed the same count of decimals. So we need helper columns which ROUNDs A and B to 8 decimals and then use those helper columns in MATCH(..,0) or VLOOKUP(.., FALSE).
At least one helper column is needed since we could round the lookup value directly within the functions. But the lookup array we can not round that way.
Example:
Formulas:
B3downwards:
=B2+TIME(0,30,0)
C2downwards:
=A2=B2
D2downwards:
=MATCH(B2,A:A,0)
E2 downwards:
=MATCH(ROUND(B2,8),G:G,0)
G2downwards:
=ROUND(A2,8)

Calculate hours outside normal working time

From my sample xls(office2007) listed below. I am trying to calculate the hours worked from 17:00 onwards. could someone show me how would I write the formula to achieve this.
Many thanks...
Leaving Time Arrival Time DeliveryTime RTB Time per Job hoursforDaysWork
09:30:00 11:05:00 11:15:00 11:15:00 01:45:00 12:00:00
11:15:00 12:15:00 12:30:00 13:30:00 02:15:00
13:30:00 15:30:00 15:45:00 15:45:00 02:15:00
15:45:00 18:15:00 18:30:00 18:30:00 02:45:00
18:30:00 19:00:00 19:45:00 21:30:00 03:00:00
Time in Excel is based upon parts of 24 (whole day) as explained in this article.
So assuming that you care about hours after 17:00, but not after midnight, the following should help you out:
=IF(C2<17/24,0,C2-17/24)*24
C2 is the cell the calculation is for, with 17/24 giving you the time for 17:00 (5pm). The *24 at the end converts the response to be in hours instead of partial day.

Resources