Calculate Time Difference Per Day Based On Criteria

PS_Richard

New Member
Joined
Nov 22, 2022
Messages
13
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi all,

I'm hoping someone might be able to give me a hand here in working out a way to get this data out. I've tried with MINIFS and MAXIFS setting to a month time frame but this only picks up the first instance and the last instance within the month where I need to work it out per day.

Here is an export of data that I need some help with.

Example.xlsx
ABCDEFGHIJKLMNO
1Site IDSite NameEquipment IDSerial NumberPool IDPool NameEvent TimeEvent Time LocalEvent Start Time LocalCharger IDEvent CodeDurationEventVPCEvent TypeAvailable
21234Warehouse A43211237899999BAL03/10/2022 04:5203/10/2022 05:5202/10/2022 19:136Pick639.52.181
31234Warehouse A43211237899999BAL03/10/2022 05:0003/10/2022 06:0003/10/2022 05:421Pick18.402/01/1900 04:480
41234Warehouse A43211237899999BAL03/10/2022 05:0103/10/2022 06:0103/10/2022 05:526Battery connect9.31.93High Voltaqe0
51234Warehouse A43211237899999BAL03/10/2022 05:0203/10/2022 06:0203/10/2022 06:016Charge Started0.32.010
61234Warehouse A43211237899999BAL03/10/2022 05:4603/10/2022 06:4603/10/2022 01:178Battery connect329.31.93High Voltaqe0
71234Warehouse A43211237899999BAL03/10/2022 05:4603/10/2022 06:4603/10/2022 06:468Charge Started0.32.010
81234Warehouse A43211237899999BAL03/10/2022 05:5003/10/2022 06:5003/10/2022 06:001Battery connect50.11.96High Voltaqe0
91234Warehouse A43211237899999BAL03/10/2022 05:5103/10/2022 06:5103/10/2022 06:501Charge Started0.82.040
101234Warehouse A43211237899999BAL03/10/2022 05:5303/10/2022 06:5302/10/2022 19:339On-charge mispick during maintenance679.42.570
111234Warehouse A43211237899999BAL03/10/2022 05:5303/10/2022 06:5302/10/2022 15:582Quarantine Exit895.32.1Battery Selected0
121234Warehouse A43211237899999BAL03/10/2022 05:5303/10/2022 06:5302/10/2022 23:304On-charge mispick during maintenance443.71.960
131234Warehouse A43211237899999BAL03/10/2022 05:5503/10/2022 06:5503/10/2022 06:532Battery connect1.82.1False Pick0
141234Warehouse A43211237899999BAL03/10/2022 05:5503/10/2022 06:5503/10/2022 06:534Battery connect1.81.96False Pick0
151234Warehouse A43211237899999BAL03/10/2022 05:5603/10/2022 06:5603/10/2022 06:552Charge Started0.82.190
161234Warehouse A43211237899999BAL03/10/2022 05:5603/10/2022 06:5603/10/2022 06:554Charge Started0.72.040
171234Warehouse A43211237899999BAL03/10/2022 06:2103/10/2022 07:2102/10/2022 23:237Gassing voltage478.71.970
181234Warehouse A43211237899999BAL03/10/2022 06:4103/10/2022 07:4102/10/2022 21:295Charge Complete6122.241
191234Warehouse A43211237899999BAL03/10/2022 06:5103/10/2022 07:5103/10/2022 07:51Status update001
201234Warehouse A43211237899999BAL03/10/2022 06:5603/10/2022 07:5603/10/2022 06:562Gassing voltage60.72.11
211234Warehouse A43211237899999BAL03/10/2022 08:5203/10/2022 09:5203/10/2022 01:1710Gassing voltage5151.951
221234Warehouse A43211237899999BAL03/10/2022 08:5703/10/2022 09:5703/10/2022 05:173Gassing voltage279.31.981
231234Warehouse A43211237899999BAL03/10/2022 09:5603/10/2022 10:5602/10/2022 23:237Charge Complete6932.232
241234Warehouse A43219873219999VNA27/10/2022 02:0327/10/2022 03:0326/10/2022 23:4911Pick193.42.170
251234Warehouse A43219873219999VNA27/10/2022 02:0427/10/2022 03:0427/10/2022 00:176Battery connect166.71.95High Voltaqe0
261234Warehouse A43219873219999VNA27/10/2022 02:0427/10/2022 03:0426/10/2022 18:255Battery connect518.91.96High Voltaqe0
271234Warehouse A43219873219999VNA27/10/2022 02:0427/10/2022 03:0427/10/2022 03:046Charge Started0.32.020
281234Warehouse A43219873219999VNA27/10/2022 02:0527/10/2022 03:0527/10/2022 03:045Charge Started0.72.040
291234Warehouse A43219873219999VNA27/10/2022 02:1227/10/2022 03:1226/10/2022 19:367Gassing voltage455.71.970
301234Warehouse A43219873219999VNA27/10/2022 02:5027/10/2022 03:5026/10/2022 18:303Charge Complete559.22.241
311234Warehouse A43219873219999VNA27/10/2022 18:0327/10/2022 19:0327/10/2022 08:301Pick193.42.170
321234Warehouse A43219873219999VNA27/10/2022 18:1027/10/2022 19:1027/10/2022 10:562Battery connect166.71.95High Voltaqe0
331234Warehouse A43219873219999VNA27/10/2022 18:1827/10/2022 19:1827/10/2022 18:4213Battery connect518.91.96High Voltaqe0
341234Warehouse A43219873219999VNA27/10/2022 18:1927/10/2022 19:1927/10/2022 19:182Charge Started0.32.020
351234Warehouse A43219873219999VNA27/10/2022 18:3127/10/2022 19:3127/10/2022 14:1813Charge Started0.72.040
361234Warehouse A43219873219999VNA27/10/2022 20:4427/10/2022 21:4427/10/2022 11:324Gassing voltage455.71.970
371234Warehouse A43219873219999VNA27/10/2022 21:0527/10/2022 22:0527/10/2022 11:509Charge Complete559.22.241
Sheet1


Based on this, as soon as a 0 (zero) appears in column O (Oscar) I need it to look at column H for the date/time the event started and also split this out by whichever Pool Name (column F) the battery is. For the first instance of Here it is 03/10/2022 06:00:27 and then on that day when column O is not a 0 happens at 03/10/2022 07:41:59 so a time difference of 1 hour 41 minutes and 32 seconds. This can happen numerous times within the day and other the month.

In the example above the next instance starts 27/10/2022 03:03:14 and ends at 27/10/2022 03:50:01 but then another occasion that day is at 27/10/2022 19:03:33 to 27/10/2022 21:44:03. Respectively this is 46 minutes and 47 seconds then 2 hours 40 minutes and 30 seconds giving a total for that day of 3 hours 27 minutes and 17 seconds.

These figures I then want to appear into a table like this.

Example.xlsx
EFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJ
2Date01/10/202202/10/202203/10/202204/10/202205/10/202206/10/202207/10/202208/10/202209/10/202210/10/202211/10/202212/10/202213/10/202214/10/202215/10/202216/10/202217/10/202218/10/202219/10/202220/10/202221/10/202222/10/202223/10/202224/10/202225/10/202226/10/202227/10/202228/10/202229/10/202230/10/202231/10/2022
3BAL102
4VNA208
Sheet2


With the duration round up to the next full minute. This is to then allow me to present in either a bar / line graph the data for the month broken down by day. I'd rather this be worked out using a formula as such as I'm not great/used Power Query and currently that training is on the back burner.

Thanks in advance for any help anyone can give.
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
A possible solution:
-in sheet2 you create the date sequence by using in F1 the formula
Code:
=SEQUENCE(,MAX(Sheet1!H:H)-MIN(Sheet1!H:H)+5,INT(MIN(Sheet1!H:H))-2)
-now create the list of Pools by using in Sheet2 E2 the formula
Code:
=UNIQUE(Sheet1!F2:F1000)
Now you can calculate the allocated time per day /per pool using in Sheet2!F2 the formula
Code:
=IFERROR(LET(ETL,Sheet1!$H$2:$H$37,cDay,F$1,cPool,$E2,Pool,Sheet1!$F$2:$F$37,AvailA,Sheet1!$O$2:$O$37,AvailB,OFFSET(AvailA,-1,0,ROWS(AvailA)+2,1),Start,IF((Pool=cPool)*(INT(ETL)=cDay)*(AvailA=0)*(AvailB>0),ETL,""),Stop,IF((Pool=cPool)*(INT(ETL)=cDay)*(AvailA>0)*(AvailB=0),ETL,""),CIP,SUM(AGGREGATE(15,6,Stop,SEQUENCE(COUNT(Stop)))-AGGREGATE(15,6,Start,SEQUENCE(COUNT(Stop)))),CIP)*1440,0)
Copy to the right for as many dates are listed, then copy this line of formulas down for as many Pools are listed

Beware that the value I calculated for Oct 27 is 3h49min, ie 229 minutes

If you need to customize the formula:
Rich (BB code):
ETL,Sheet1!$H$2:$H$37    This is the EventTimeLocal Column in Sheet1
cDay,F$1                 This is the Day under evaluation
cPool,$E2                This is the Pool under evaluation
Pool,Sheet1!$F$2:$F$37   This is the Pool Column in Sheet1
AvailA,Sheet1!$O$2:$O$37 This is the Available Column in Sheet1


Try...

Cartel1
EFGHIJKLMNOPQ
101-ott-2202-ott-2203-ott-2204-ott-2205-ott-2206-ott-2207-ott-2208-ott-2209-ott-2210-ott-2211-ott-2212-ott-22
2BAL - - 101 - - - - - - - - -
3VNA - - - - - - - - - - - -
40
5
6
7
Sheet2
Cell Formulas
RangeFormula
F1:AH1F1=SEQUENCE(,MAX(Sheet1!H:H)-MIN(Sheet1!H:H)+5,INT(MIN(Sheet1!H:H))-2)
E2:E4E2=UNIQUE(Sheet1!F2:F1000)
F2:Q3F2=IFERROR(LET(ETL,Sheet1!$H$2:$H$37,cDay,F$1,cPool,$E2,Pool,Sheet1!$F$2:$F$37,AvailA,Sheet1!$O$2:$O$37,AvailB,OFFSET(AvailA,-1,0,ROWS(AvailA)+2,1),Start,IF((Pool=cPool)*(INT(ETL)=cDay)*(AvailA=0)*(AvailB>0),ETL,""),Stop,IF((Pool=cPool)*(INT(ETL)=cDay)*(AvailA>0)*(AvailB=0),ETL,""),CIP,SUM(AGGREGATE(15,6,Stop,SEQUENCE(COUNT(Stop)))-AGGREGATE(15,6,Start,SEQUENCE(COUNT(Stop)))),CIP)*1440,0)
Dynamic array formulas.
 
Last edited:
Upvote 0
Thanks @Anthony47 I've given that a whirl and at first glance its doing something but when I pick a few days to sanity check manually things aren't adding up right. I've got some data below to show what I mean.

This first section is some raw data (omitted sensitive details) and limited the data to a 'transaction' as such where the calculation should pick up due to the Available in column O has changed from a positive number to 0.

Raw Data
Example Sheet.xlsx
ABCDEFGHIJKLMNOPQRSTUVW
1Site IdSite NameEquipment IdSerial NumberPool IdPool NameEvent TimeEvent Time LocalEvent Start Time LocalCharger IdEvent CodeDurationEventVPCEvent TypeAvailableAvailable CooledChargingCon Not ChargingNo BatteryQuarantineUnknownSource Data FiledbId
21234Warehouse A80274507053135150C BAL18/11/2021 03:0518/11/2021 03:0517/11/2021 19:189Gassing voltage4671.973150300I45070531-3220416-1.csv393391811
31234Warehouse A80274507053135150C BAL18/11/2021 10:1618/11/2021 10:1618/11/2021 10:16Status update005230300I45070531-3221616-1.csv393490606
41234Warehouse A80274507053135150C BAL18/11/2021 10:5118/11/2021 10:5118/11/2021 01:241Charge Complete5672.215130300I45070531-3221616-1.csv393490615
51234Warehouse A80274507053135150C BAL18/11/2021 17:0618/11/2021 17:0618/11/2021 11:544Gassing voltage311.41.941160400I45070531-3222216-1.csv393541933
61234Warehouse A80274507053135151VNA18/11/2021 00:2218/11/2021 00:2217/11/2021 17:419Pick4012.1552301000I45070531-3220416-1.csv393391799
71234Warehouse A80274507053135151VNA18/11/2021 00:2918/11/2021 00:2917/11/2021 20:5510Gassing voltage213.62.0352301000I45070531-3220416-1.csv393391800
81234Warehouse A80274507053135151VNA18/11/2021 00:3218/11/2021 00:3217/11/2021 22:222Battery connect129.82.01High Voltaqe5231900I45070531-3220416-1.csv393391801
91234Warehouse A80274507053135151VNA18/11/2021 00:3318/11/2021 00:3318/11/2021 00:322Charge Started1.32.15240900I45070531-3220416-1.csv393391802
101234Warehouse A80274507053135151VNA18/11/2021 01:0618/11/2021 01:0617/11/2021 19:474Gassing voltage319.32.015440900I45070531-3220416-1.csv393391803
111234Warehouse A80274507053135151VNA18/11/2021 02:5918/11/2021 02:5918/11/2021 00:229Battery connect156.92.04High Voltaqe5541800I45070531-3220416-1.csv393391808
121234Warehouse A80274507053135151VNA18/11/2021 02:5918/11/2021 02:5917/11/2021 17:583Pick541.42.144441900I45070531-3220416-1.csv393391809
131234Warehouse A80274507053135151VNA18/11/2021 03:0018/11/2021 03:0018/11/2021 02:599Charge Started1.42.124450900I45070531-3220416-1.csv393391810
141234Warehouse A80274507053135151VNA18/11/2021 03:0518/11/2021 03:0517/11/2021 18:056Pick540.12.1533501000I45070531-3220416-1.csv393391812
151234Warehouse A80274507053135151VNA18/11/2021 03:0518/11/2021 03:0518/11/2021 02:593Battery connect5.72.14False Pick3351900I45070531-3220416-1.csv393391813
161234Warehouse A80274507053135151VNA18/11/2021 03:0618/11/2021 03:0618/11/2021 03:053Charge Started1.22.283360900I45070531-3220416-1.csv393391814
171234Warehouse A80274507053135151VNA18/11/2021 03:0818/11/2021 03:0818/11/2021 03:063Gassing voltage2.12.143360900I45070531-3220416-1.csv393391815
181234Warehouse A80274507053135151VNA18/11/2021 03:1818/11/2021 03:1817/11/2021 20:5510Charge Complete382.62.214350900I45070531-3220416-1.csv393391817
191234Warehouse A80274507053135151VNA18/11/2021 03:1818/11/2021 03:1818/11/2021 03:056Battery connect12.92High Voltaqe4351800I45070531-3220416-1.csv393391818
201234Warehouse A80274507053135151VNA18/11/2021 03:1818/11/2021 03:1817/11/2021 22:267On-charge mispick291.61.724341900I45070531-3220416-1.csv393391819
211234Warehouse A80274507053135151VNA18/11/2021 03:1918/11/2021 03:1918/11/2021 03:186Charge Started1.52.084350900I45070531-3220416-1.csv393391820
221234Warehouse A80274507053135151VNA18/11/2021 04:1318/11/2021 04:1317/11/2021 19:474Charge Complete505.72.235340900I45070531-3220416-1.csv393391822
231234Warehouse A80274507053135151VNA18/11/2021 04:4718/11/2021 04:4718/11/2021 03:063Charge Complete100.82.196330900I45070531-3221016-1.csv393439215
241234Warehouse A80274507053135151VNA18/11/2021 05:0618/11/2021 05:0618/11/2021 03:187Battery connect108.32.02High Voltaqe6331800I45070531-3221016-1.csv393439216
251234Warehouse A80274507053135151VNA18/11/2021 05:0618/11/2021 05:0617/11/2021 18:458Pick621.32.155231900I45070531-3221016-1.csv393439217
261234Warehouse A80274507053135151VNA18/11/2021 05:0818/11/2021 05:0818/11/2021 05:067Charge Started1.32.15240900I45070531-3221016-1.csv393439218
271234Warehouse A80274507053135151VNA18/11/2021 05:3818/11/2021 05:3818/11/2021 05:068Battery connect31.72.03High Voltaqe5241800I45070531-3221016-1.csv393439219
281234Warehouse A80274507053135151VNA18/11/2021 05:3918/11/2021 05:3918/11/2021 05:388Charge Started0.82.15250800I45070531-3221016-1.csv393439220
291234Warehouse A80274507053135151VNA18/11/2021 05:3918/11/2021 05:3917/11/2021 18:591Pick639.42.144150900I45070531-3221016-1.csv393439221
301234Warehouse A80274507053135151VNA18/11/2021 05:4318/11/2021 05:4318/11/2021 00:332Gassing voltage310.32.014150900I45070531-3221016-1.csv393439222
311234Warehouse A80274507053135151VNA18/11/2021 05:4418/11/2021 05:4417/11/2021 19:135Pick631.12.1530501000I45070531-3221016-1.csv393439223
321234Warehouse A80274507053135151VNA18/11/2021 05:5118/11/2021 05:5118/11/2021 05:391Battery connect12.62.01High Voltaqe3051900I45070531-3221016-1.csv393439224
331234Warehouse A80274507053135151VNA18/11/2021 05:5318/11/2021 05:5318/11/2021 05:511Charge Started1.32.093060900I45070531-3221016-1.csv393439225
341234Warehouse A80274507053135151VNA18/11/2021 06:2618/11/2021 06:2618/11/2021 03:1810Pick188.92.1920601000I45070531-3221016-1.csv393439227
351234Warehouse A80274507053135151VNA18/11/2021 06:2918/11/2021 06:2918/11/2021 05:445Battery connect45.82High Voltaqe2061900I45070531-3221016-1.csv393439228
361234Warehouse A80274507053135151VNA18/11/2021 06:3118/11/2021 06:3118/11/2021 06:295Charge Started1.32.082070900I45070531-3221016-1.csv393439229
371234Warehouse A80274507053135151VNA18/11/2021 07:1418/11/2021 07:1418/11/2021 04:134Pick181.42.210701000I45070531-3221016-1.csv393439236
381234Warehouse A80274507053135151VNA18/11/2021 07:1518/11/2021 07:1518/11/2021 03:009Gassing voltage254.92.0410701000I45070531-3221016-1.csv393439237
391234Warehouse A80274507053135151VNA18/11/2021 07:2418/11/2021 07:2418/11/2021 07:144Battery connect9.82.05High Voltaqe1071900I45070531-3221016-1.csv393439238
401234Warehouse A80274507053135151VNA18/11/2021 07:2518/11/2021 07:2518/11/2021 07:244Charge Started12.121080900I45070531-3221016-1.csv393439239
411234Warehouse A80274507053135151VNA18/11/2021 08:2418/11/2021 08:2418/11/2021 04:473Pick217.42.1400801000I45070531-3221016-1.csv393439240
421234Warehouse A80274507053135151VNA18/11/2021 08:2818/11/2021 08:2818/11/2021 06:2610Battery connect121.32.02High Voltaqe0081900I45070531-3221016-1.csv393439241
431234Warehouse A80274507053135151VNA18/11/2021 08:2918/11/2021 08:2918/11/2021 08:2810Charge Started1.42.110090900I45070531-3221016-1.csv393439242
441234Warehouse A80274507053135151VNA18/11/2021 08:3218/11/2021 08:3218/11/2021 03:196Gassing voltage312.520090900I45070531-3221016-1.csv393439243
451234Warehouse A80274507053135151VNA18/11/2021 08:5518/11/2021 08:5518/11/2021 00:332Charge Complete502.12.231080900I45070531-3221016-1.csv393439244
461234Warehouse A80274507053135151VNA18/11/2021 10:0918/11/2021 10:0918/11/2021 07:254Gassing voltage164.32.051080900I45070531-3221016-1.csv393439249
471234Warehouse A80274507053135151VNA18/11/2021 10:1518/11/2021 10:1518/11/2021 03:009Charge Complete434.92.232070900I45070531-3221016-1.csv393439250
481234Warehouse A80274507053135151VNA18/11/2021 10:1618/11/2021 10:1618/11/2021 10:16Status update002070900I45070531-3221616-1.csv393490607
491234Warehouse A80274507053135151VNA18/11/2021 10:2918/11/2021 10:2918/11/2021 05:087Gassing voltage321.12.022070900I45070531-3221616-1.csv393490608
501234Warehouse A80274507053135151VNA18/11/2021 10:5018/11/2021 10:5018/11/2021 08:243Battery connect145.82.01High Voltaqe2071800I45070531-3221616-1.csv393490612
511234Warehouse A80274507053135151VNA18/11/2021 10:5018/11/2021 10:5018/11/2021 08:552Pick115.42.21071900I45070531-3221616-1.csv393490613
521234Warehouse A80274507053135151VNA18/11/2021 10:5118/11/2021 10:5118/11/2021 05:531Gassing voltage297.82.011071900I45070531-3221616-1.csv393490614
531234Warehouse A80274507053135151VNA18/11/2021 10:5218/11/2021 10:5218/11/2021 10:503Charge Started1.62.091080900I45070531-3221616-1.csv393490616
541234Warehouse A80274507053135151VNA18/11/2021 11:2018/11/2021 11:2018/11/2021 03:196Charge Complete480.42.22070900I45070531-3221616-1.csv393490617
551234Warehouse A80274507053135151VNA18/11/2021 11:2318/11/2021 11:2318/11/2021 10:159Pick67.22.210701000I45070531-3221616-1.csv393490618
561234Warehouse A80274507053135151VNA18/11/2021 12:0018/11/2021 12:0018/11/2021 06:315Gassing voltage329.6210701000I45070531-3221616-1.csv393490622
571234Warehouse A80274507053135151VNA18/11/2021 12:1618/11/2021 12:1618/11/2021 10:502Battery connect85.72.01High Voltaqe1071900I45070531-3221616-1.csv393490623
581234Warehouse A80274507053135151VNA18/11/2021 12:1818/11/2021 12:1818/11/2021 12:162Charge Started1.62.091080900I45070531-3221616-1.csv393490624
591234Warehouse A80274507053135151VNA18/11/2021 12:3318/11/2021 12:3318/11/2021 05:398Gassing voltage414.52.031080900I45070531-3221616-1.csv393490625
601234Warehouse A80274507053135151VNA18/11/2021 13:3318/11/2021 13:3318/11/2021 08:2910Gassing voltage303.52.021080900I45070531-3221616-1.csv393490626
611234Warehouse A80274507053135151VNA18/11/2021 13:5718/11/2021 13:5718/11/2021 05:087Charge Complete529.12.212070900I45070531-3221616-1.csv393490627
621234Warehouse A80274507053135151VNA18/11/2021 14:0018/11/2021 14:0018/11/2021 05:531Charge Complete4872.213060900I45070531-3221616-1.csv393490628
631234Warehouse A80274507053135151VNA18/11/2021 14:1718/11/2021 14:1718/11/2021 07:254Charge Complete412.42.234050900I45070531-3221616-1.csv393490630
641234Warehouse A80274507053135151VNA18/11/2021 15:1118/11/2021 15:1118/11/2021 10:523Gassing voltage259.62.014050900I45070531-3221616-1.csv393490631
651234Warehouse A80274507053135151VNA18/11/2021 15:2718/11/2021 15:2718/11/2021 11:229Battery connect244.22High Voltaqe4051800I45070531-3221616-1.csv393490632
661234Warehouse A80274507053135151VNA18/11/2021 15:2718/11/2021 15:2718/11/2021 11:206Pick247.62.153051900I45070531-3221616-1.csv393490633
671234Warehouse A80274507053135151VNA18/11/2021 15:2818/11/2021 15:2818/11/2021 15:279Charge Started1.32.083060900I45070531-3221616-1.csv393490634
681234Warehouse A80274507053135151VNA18/11/2021 15:3018/11/2021 15:3018/11/2021 15:276Battery connect2.72.15False Pick3061800I45070531-3221616-1.csv393490635
691234Warehouse A80274507053135151VNA18/11/2021 15:3118/11/2021 15:3118/11/2021 13:577Pick942.192061900I45070531-3221616-1.csv393490636
701234Warehouse A80274507053135151VNA18/11/2021 15:3118/11/2021 15:3118/11/2021 15:306Charge Started1.22.292070900I45070531-3221616-1.csv393490637
711234Warehouse A80274507053135151VNA18/11/2021 15:3318/11/2021 15:3318/11/2021 15:316Gassing voltage22.152070900I45070531-3221616-1.csv393490638
721234Warehouse A80274507053135151VNA18/11/2021 15:3618/11/2021 15:3618/11/2021 05:398Charge Complete597.42.233060900I45070531-3221616-1.csv393490639
731234Warehouse A80274507053135151VNA18/11/2021 15:4118/11/2021 15:4118/11/2021 06:315Charge Complete550.42.224050900I45070531-3221616-1.csv393490640
741234Warehouse A80274507053135151VNA18/11/2021 15:5018/11/2021 15:5018/11/2021 14:001Pick110.22.1830501000I45070531-3221616-1.csv393490645
751234Warehouse A80274507053135151VNA18/11/2021 16:0018/11/2021 16:0018/11/2021 15:317Battery connect29.72High Voltaqe3051900I45070531-3221616-1.csv393490646
761234Warehouse A80274507053135151VNA18/11/2021 16:0218/11/2021 16:0218/11/2021 16:007Charge Started1.62.083060900I45070531-3221616-1.csv393490647
771234Warehouse A80274507053135151VNA18/11/2021 16:0418/11/2021 16:0418/11/2021 14:174Pick106.62.220601000I45070531-3221616-1.csv393490648
781234Warehouse A80274507053135151VNA18/11/2021 16:0818/11/2021 16:0818/11/2021 15:501Battery connect18.22High Voltaqe2061900I45070531-3221616-1.csv393490649
791234Warehouse A80274507053135151VNA18/11/2021 16:1018/11/2021 16:1018/11/2021 16:081Charge Started1.62.082070900I45070531-3221616-1.csv393490650
801234Warehouse A80274507053135151VNA18/11/2021 16:1218/11/2021 16:1218/11/2021 15:368Pick35.72.210701000I45070531-3221616-1.csv393490651
811234Warehouse A80274507053135151VNA18/11/2021 16:1218/11/2021 16:1218/11/2021 16:044Battery connect82.02High Voltaqe1071900I45070531-3221616-1.csv393490652
821234Warehouse A80274507053135151VNA18/11/2021 16:1418/11/2021 16:1418/11/2021 16:124Charge Started1.62.11080900I45070531-3221616-1.csv393490653
831234Warehouse A80274507053135151VNA18/11/2021 16:2218/11/2021 16:2218/11/2021 08:2910Charge Complete472.72.212070900I45070531-3222216-1.csv393541931
841234Warehouse A80274507053135151VNA18/11/2021 17:0618/11/2021 17:0618/11/2021 12:182Gassing voltage288.42.012070900I45070531-3222216-1.csv393541934
851234Warehouse A80274507053135151VNA18/11/2021 17:1218/11/2021 17:1218/11/2021 15:316Charge Complete1012.213060900I45070531-3222216-1.csv393541935
861234Warehouse A80274507053135151VNA18/11/2021 17:5718/11/2021 17:5718/11/2021 10:523Charge Complete4252.194050900I45070531-3222216-1.csv393541942
871234Warehouse A80274507053135151VNA18/11/2021 19:0318/11/2021 19:0318/11/2021 15:415Pick201.92.1930501000I45070531-3222216-1.csv393541946
881234Warehouse A80274507053135151VNA18/11/2021 19:0318/11/2021 19:0318/11/2021 16:128Battery connect171.32.01High Voltaqe3051900I45070531-3222216-1.csv393541947
891234Warehouse A80274507053135151VNA18/11/2021 19:0418/11/2021 19:0418/11/2021 19:038Charge Started0.92.083060900I45070531-3222216-1.csv393541948
901234Warehouse A80274507053135151VNA18/11/2021 19:1818/11/2021 19:1818/11/2021 19:035Battery connect14.92.05High Voltaqe3061800I45070531-3222216-1.csv393541950
911234Warehouse A80274507053135151VNA18/11/2021 19:1818/11/2021 19:1818/11/2021 16:2210Pick176.62.182061900I45070531-3222216-1.csv393541951
921234Warehouse A80274507053135151VNA18/11/2021 19:1918/11/2021 19:1918/11/2021 19:185Charge Started1.32.132070900I45070531-3222216-1.csv393541952
931234Warehouse A80274507053135151VNA18/11/2021 19:5318/11/2021 19:5318/11/2021 12:182Charge Complete455.62.193060900I45070531-3222216-1.csv393541954
941234Warehouse A80274507053135151VNA18/11/2021 20:1518/11/2021 20:1518/11/2021 16:144Gassing voltage241.12.023060900I45070531-3222216-1.csv393541955
951234Warehouse A80274507053135151VNA18/11/2021 20:2818/11/2021 20:2818/11/2021 16:027Gassing voltage266.423060900I45070531-3222216-1.csv393541957
961234Warehouse A80274507053135151VNA18/11/2021 20:3618/11/2021 20:3618/11/2021 15:289Gassing voltage308.223060900I45070531-3222216-1.csv393541958
971234Warehouse A80274507053135151VNA18/11/2021 20:4618/11/2021 20:4618/11/2021 16:101Gassing voltage276.523060900I45070531-3222216-1.csv393541959
981234Warehouse A80274507053135151VNA18/11/2021 22:4218/11/2021 22:4218/11/2021 19:195Gassing voltage203.42.053060900I45070531-3230416-1.csv393592748
991234Warehouse A80274507053135151VNA18/11/2021 23:0018/11/2021 23:0018/11/2021 16:144Charge Complete406.72.194050900I45070531-3230416-1.csv393592751
1001234Warehouse A80274507053135151VNA18/11/2021 23:1418/11/2021 23:1418/11/2021 16:027Charge Complete431.92.185140900I45070531-3230416-1.csv393592752
1011234Warehouse A80274507053135151VNA18/11/2021 23:3418/11/2021 23:3418/11/2021 16:101Charge Complete444.12.186130900I45070531-3230416-1.csv393592753
1021234Warehouse A80274507053135150C BAL17/07/2022 18:1017/07/2022 19:1017/07/2022 19:0110Battery connect9.11.94High Voltaqe1041230I45070531-1981851-1.csv433317672
1031234Warehouse A80274507053135150C BAL17/07/2022 18:1117/07/2022 19:1117/07/2022 19:1010Charge Started0.32.011050230I45070531-1981851-1.csv433317673
1041234Warehouse A80274507053135150C BAL17/07/2022 20:3817/07/2022 21:3817/07/2022 16:487Pick289.42.20050330I45070531-1990051-1.csv433342110
1051234Warehouse A80274507053135150C BAL17/07/2022 20:4017/07/2022 21:4017/07/2022 19:086Battery connect151.81.92High Voltaqe0051230I45070531-1990051-1.csv433342111
1061234Warehouse A80274507053135150C BAL17/07/2022 20:4017/07/2022 21:4017/07/2022 21:406Charge Started0.320060230I45070531-1990051-1.csv433342112
1071234Warehouse A80274507053135150C BAL17/07/2022 22:1317/07/2022 23:1317/07/2022 17:555Gassing voltage317.41.950060230I45070531-1990051-1.csv433342116
1081234Warehouse A80274507053135150C BAL17/07/2022 22:5917/07/2022 23:5917/07/2022 15:299Gassing voltage510.51.980060230I45070531-1990051-1.csv433342117
1091234Warehouse A80274507053135150C BAL17/07/2022 23:3718/07/2022 00:3717/07/2022 21:387Battery connect179.31.95High Voltaqe0061130I45070531-1990051-1.csv433342122
1101234Warehouse A80274507053135150C BAL17/07/2022 23:3718/07/2022 00:3718/07/2022 00:377Charge Started0.32.030070130I45070531-1990051-1.csv433342123
1111234Warehouse A80274507053135150C BAL17/07/2022 23:4918/07/2022 00:4917/07/2022 17:555Zero Available Pick413.83.230060230I45070531-1990051-1.csv433342124
1121234Warehouse A80274507053135150C BAL18/07/2022 01:2718/07/2022 02:2717/07/2022 15:299Charge Complete658.82.231050230I45070531-1990651-1.csv433367642
1131234Warehouse A80274507053135150C BAL18/07/2022 01:4218/07/2022 02:4217/07/2022 18:322Gassing voltage490.41.931050230I45070531-1990651-1.csv433367643
Sheet1



I've been able to get all the formulas into sheet 2 to work in the fashion you have given. Only difference for this test is that I manually inputted the dates at the top row for ease of checking.

Example Sheet.xlsx
ABCDE
1Pool / Date18/11/202116/08/202217/08/202218/08/2022
2C BAL0000
3VNA30.583333000
4
5
6
708:24:5621:38:05
808:28:1321:40:35
908:29:3421:40:50
1008:32:1423:13:19
1123:59:35
1200:37:22
1300:37:39
1400:49:43
15
1600:07:18#########
17
1803:11:38
1900:08:0003:12:00
208192
21
22Answer should be 8Answer should be 192 in C BAL
Sheet2
Cell Formulas
RangeFormula
A2:A3A2=UNIQUE(Sheet1!F2:F101)
B2:E2,C3:E3B2=IFERROR(LET(ETL,Sheet1!$H$2:$H$112,cDay,B$1,cPool,$A2,Pool,Sheet1!$F$2:$F$101,AvailA,Sheet1!$O$2:$O$112,AvailB,OFFSET(AvailA,-1,0,ROWS(AvailA)+2,1),Start,IF((Pool=cPool)*(INT(ETL)=cDay)*(AvailA=0)*(AvailB>0),ETL,""),Stop,IF((Pool=cPool)*(INT(ETL)=cDay)*(AvailA>0)*(AvailB=0),ETL,""),CIP,SUM(AGGREGATE(15,6,Stop,SEQUENCE(COUNT(Stop)))-AGGREGATE(15,6,Start,SEQUENCE(COUNT(Stop)))),CIP)*1440,0)
B3B3=IFERROR(LET(ETL,Sheet1!$H$2:$H$101,cDay,B$1,cPool,$A3,Pool,Sheet1!$F$2:$F$101,AvailA,Sheet1!$O$2:$O$101,AvailB,OFFSET(AvailA,-1,0,ROWS(AvailA)+2,1),Start,IF((Pool=cPool)*(INT(ETL)=cDay)*(AvailA=0)*(AvailB>0),ETL,""),Stop,IF((Pool=cPool)*(INT(ETL)=cDay)*(AvailA>0)*(AvailB=0),ETL,""),CIP,SUM(AGGREGATE(15,6,Stop,SEQUENCE(COUNT(Stop)))-AGGREGATE(15,6,Start,SEQUENCE(COUNT(Stop)))),CIP)*1440,0)
B16B16=B10-B7
D16D16=D14-D7
Dynamic array formulas.


As shown above its getting data for the time duration on the 18-11-2021 and marking it as 30.58 yet when manually checking I have it at 8 minutes. Likewise on the other date I've picked which is the 17-08-2022 which could be an issue due to it going from one day to another and I know Excel can be funny when it comes to time being taken away and causing a negative (as seen in cell D16) so below I have shown manually what it should look like to then see how many minutes it could be.

My original data set is over 40,000 rows long, so one of the ideas I had was to remove all instances when column O is not a zero to see if the formulas would work then but alas it doesn't pick up anything as I guess this is due to it looking for a non zero result.

Again, I'm grateful for the help you've been able to give so far so hoping that by giving some more information here it might help either yourself or someone else?

Thanks
 
Upvote 0
While I disagree (or I misunderstood the question) about the result for 18-Nov-2021 (it is 31 minutes), I agree that Start & Stop at midnight is a problem, with that formula

I therefore decided to switch to a User Defined Function that corresponds to the following code:
VBA Code:
Function PSR(ByRef BigTbl As Range, ByRef PooList As Range, ByRef DtList As Range, Optional ByVal DBG As Boolean = False) As Variant
Dim bgArr, etlArr, plArr, avArr
Dim oArr(), I As Long, J As Long, K As Long
Dim cPool As String, cDay As Date, fvStop As Date, fvStart As Date
'
etlArr = BigTbl.Cells(1, 8).Resize(BigTbl.Rows.Count, 1).Value      'Event Local Time
plArr = BigTbl.Cells(1, 6).Resize(BigTbl.Rows.Count, 1).Value       'Pool name
avArr = BigTbl.Cells(1, 15).Resize(BigTbl.Rows.Count + 2, 1).Value  'Available
ReDim oArr(1 To PooList.Rows.Count, 1 To DtList.Columns.Count)
'
For I = 1 To DtList.Columns.Count
    cDay = DtList.Cells(1, I)
    For J = 1 To PooList.Rows.Count
        cPool = PooList.Cells(J, 1)
        For K = 2 To UBound(etlArr)
            If Int(etlArr(K, 1)) = cDay And plArr(K, 1) = cPool And avArr(K, 1) = 0 And avArr(K - 1, 1) > 0 Then
                fvStart = etlArr(K, 1)          'Start time detected
            End If
            If Int(etlArr(K, 1)) = cDay And plArr(K, 1) = cPool And avArr(K, 1) > 0 And avArr(K - 1, 1) = 0 Then
                fvStop = etlArr(K, 1)
            End If
            If fvStart > 0 And fvStop > 0 Then
                If DBG Then
                    oArr(J, I) = oArr(J, I) & fvStart & "--" & fvStop & " / "
                Else
                    oArr(J, I) = oArr(J, I) + fvStop - fvStart
                End If
                fvStart = 0: fvStop = 0
            End If
        Next K
        If fvStart > 0 And fvStop = 0 Then      'Start but no Stop: till 24:00
            If DBG Then
                oArr(J, I) = oArr(J, I) & fvStart & "--" & "To 24:00" & " / "
            Else
                oArr(J, I) = oArr(J, I) - fvStart + Int(fvStart + 1)
            End If
            fvStart = 0: fvStop = 0
        End If
        If fvStart = 0 And fvStop > 0 Then      'Stop but no Start: from 0:00
            If DBG Then
                oArr(J, I) = oArr(J, I) & "From 0:00" & "--" & fvStop & " / "
            Else
                oArr(J, I) = oArr(J, I) + fvStop - Int(fvStop)
            End If
            fvStart = 0: fvStop = 0
        End If
    Next J
Next I
If DBG = False Then
    For I = 1 To UBound(oArr)
        For J = 1 To UBound(oArr, 2)
            oArr(I, J) = oArr(I, J) * 1440
        Next J
    Next I
End If
PSR = oArr
End Function
Insert this code into a Standard Module of your vba project; then return to Excel.
At this point you have available the function PSR, with the following syntax
Excel Formula:
PSR(AddressOfTheBigTable, AddressOfThePoolList, AddressForTheDaysList [optional Debug, default is False])

Having created the list of dates in Sheet2, F1 to IR1
Having created the list of Pools in Sheet2, E2:E3
The formula I set in F2 is
Excel Formula:
=PSR(Sheet1!A1:O200,E2:E3,F1:IR1)

This returns all the results; namely I got
18-Nov-2021 , VNA: 31 minutes (this come from starting 18/11/2021 08:24:00 and ending 18/11/2021 08:55:00)
17-Jul-2022 , C BAL: 142 min (this comes from starting at 17/07/2022 21:38:00 and ending at 24:00)
18-Jul-2022 , C BAL: 147 min (this comes from starting at 18/07/2022 at 0:00 and ending at 2:27)

The function PST can be invoked with a "debug" parametre: if you use in F2
Excel Formula:
=PSR(Sheet1!A1:O200,E2:E3,F1:IR1,TRUE)
then you will get the info on how the result is calculated; you need to enlarge the columns to see the information
For 17 and 18-Jul-2022 I got:
17th: 17/07/2022 21:38:00--To 24:00 /
18th: From 0:00--18/07/2022 02:27:00 /

Try...
 
Last edited:
Upvote 0
Solution
Apologies @Anthony47, you are right with the timings/durations. The VBA script works perfecting and doesn't cause my work laptop to freeze! Thank you so much for doing this for me as it'll save me hours trying to do it manually.
 
Upvote 0

Forum statistics

Threads
1,214,825
Messages
6,121,787
Members
449,049
Latest member
greyangel23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top