Finding values between a time range

MAP77

Board Regular
Joined
Sep 19, 2018
Messages
60
Office Version
  1. 365
Platform
  1. Windows
Hi guys,

I need to find a couple of different things with this set of data.
1) Create a new column called 'day' or 'night' where excel finds all the values between the time 05:30 and 18:00 and calls them 'day' and all the values outside that time block 'night'.
2) Find the average of the values in column B for each day between the hours of 05:30 and 18:00. EG. 1/10/22 would be an average of 21.3489, 2/10/22 would be an average of 20.8088 etc.

I'm not sure if I should do (1) in power query. If so, what would be the formula?

Book1
AB
1TimestampTotal Avg of Power (kW)
21/10/2022 0:0050.31894
31/10/2022 0:3048.73556
41/10/2022 1:0041.71369
51/10/2022 1:3040.04663
61/10/2022 2:0046.63919
71/10/2022 2:3047.45826
81/10/2022 3:0051.39905
91/10/2022 3:3047.71795
101/10/2022 4:0024.10075
111/10/2022 4:3022.72165
121/10/2022 5:0025.50718
131/10/2022 5:3019.47058
141/10/2022 6:0023.97777
151/10/2022 6:3019.45572
161/10/2022 7:0023.74369
171/10/2022 7:3018.40715
181/10/2022 8:0023.35959
191/10/2022 8:3018.96019
201/10/2022 9:0023.91301
211/10/2022 9:3017.59056
221/10/2022 10:0023.3182
231/10/2022 10:3019.21594
241/10/2022 11:0024.295
251/10/2022 11:3018.74359
261/10/2022 12:0024.78997
271/10/2022 12:3018.7614
281/10/2022 13:0023.62567
291/10/2022 13:3019.25247
301/10/2022 14:0024.00009
311/10/2022 14:3017.35174
321/10/2022 15:0023.45803
331/10/2022 15:3019.49955
341/10/2022 16:0023.8039
351/10/2022 16:3018.4821
361/10/2022 17:0024.41319
371/10/2022 17:3018.03606
381/10/2022 18:0025.14828
391/10/2022 18:3020.79991
401/10/2022 19:0025.17342
411/10/2022 19:3020.28958
421/10/2022 20:0025.30734
431/10/2022 20:3021.1434
441/10/2022 21:0026.2569
451/10/2022 21:3020.76921
461/10/2022 22:0025.2568
471/10/2022 22:3021.36637
481/10/2022 23:0026.23097
491/10/2022 23:3021.00897
502/10/2022 0:0024.64072
512/10/2022 0:3021.53037
522/10/2022 1:0025.90326
532/10/2022 1:3020.68053
542/10/2022 2:0026.29263
552/10/2022 2:3019.58213
562/10/2022 3:0024.48504
572/10/2022 3:3021.60895
582/10/2022 4:0025.0754
592/10/2022 4:3020.43373
602/10/2022 5:0025.82612
612/10/2022 5:3018.91279
622/10/2022 6:0023.04572
632/10/2022 6:3019.37435
642/10/2022 7:0023.38685
652/10/2022 7:3018.81967
662/10/2022 8:0022.26641
672/10/2022 8:3018.19895
682/10/2022 9:0022.79994
692/10/2022 9:3017.75849
702/10/2022 10:0022.61499
712/10/2022 10:3017.72912
722/10/2022 11:0022.47978
732/10/2022 11:3018.40815
742/10/2022 12:0024.00994
752/10/2022 12:3018.24447
762/10/2022 13:0021.60704
772/10/2022 13:3018.90856
782/10/2022 14:0023.22153
792/10/2022 14:3019.15069
802/10/2022 15:0023.48298
812/10/2022 15:3017.904
822/10/2022 16:0022.29922
832/10/2022 16:3019.27028
842/10/2022 17:0023.40998
852/10/2022 17:3018.1261
862/10/2022 18:0025.60093
872/10/2022 18:3020.01902
882/10/2022 19:0024.392
892/10/2022 19:3021.62492
902/10/2022 20:0026.04565
912/10/2022 20:3019.89793
922/10/2022 21:0024.47673
932/10/2022 21:3020.99338
942/10/2022 22:0025.83778
952/10/2022 22:3020.79955
962/10/2022 23:0025.49927
972/10/2022 23:3020.53727
983/10/2022 0:0025.77991
993/10/2022 0:3021.96724
1003/10/2022 1:0023.8442
1013/10/2022 1:3021.14151
1023/10/2022 2:0026.6441
1033/10/2022 2:3020.25448
1043/10/2022 3:0024.75333
1053/10/2022 3:3022.45333
1063/10/2022 4:0026.05707
1073/10/2022 4:3022.58693
1083/10/2022 5:0026.01925
1093/10/2022 5:3019.5637
1103/10/2022 6:0023.35992
1113/10/2022 6:3018.67553
1123/10/2022 7:0022.05696
1133/10/2022 7:3017.99264
1143/10/2022 8:0022.40223
1153/10/2022 8:3018.11939
1163/10/2022 9:0023.09753
1173/10/2022 9:3018.88339
1183/10/2022 10:0021.72426
1193/10/2022 10:3018.70486
1203/10/2022 11:0022.47323
1213/10/2022 11:3019.52072
1223/10/2022 12:0023.60704
1233/10/2022 12:3017.16556
1243/10/2022 13:0022.99702
1253/10/2022 13:3019.45797
1263/10/2022 14:0022.16807
1273/10/2022 14:3018.87158
1283/10/2022 15:0022.1818
1293/10/2022 15:3019.52419
1303/10/2022 16:0023.72906
1313/10/2022 16:3018.64053
1323/10/2022 17:0023.74332
1333/10/2022 17:3020.6988
1343/10/2022 18:0026.47136
1353/10/2022 18:3022.42386
1363/10/2022 19:0027.74197
1373/10/2022 19:3022.35145
1383/10/2022 20:0026.34637
1393/10/2022 20:3023.61971
1403/10/2022 21:0027.09262
1413/10/2022 21:3023.44937
1423/10/2022 22:0027.15357
1433/10/2022 22:3022.58038
1443/10/2022 23:0027.13214
1453/10/2022 23:3023.3851
1464/10/2022 0:0025.47184
1474/10/2022 0:3022.91429
1484/10/2022 1:0026.56001
1494/10/2022 1:3024.3497
1504/10/2022 2:0025.49595
1514/10/2022 2:3022.68093
1524/10/2022 3:0030.14696
1534/10/2022 3:3039.1493
1544/10/2022 4:0049.31453
1554/10/2022 4:3044.61409
1564/10/2022 5:0089.67751
1574/10/2022 5:30109.8451
1584/10/2022 6:00113.8321
1594/10/2022 6:30114.4188
1604/10/2022 7:00119.5391
1614/10/2022 7:30119.8405
1624/10/2022 8:00104.8957
1634/10/2022 8:30110.8639
1644/10/2022 9:00123.3824
1654/10/2022 9:30130.0801
1664/10/2022 10:00127.059
1674/10/2022 10:30119.2714
1684/10/2022 11:00103.917
1694/10/2022 11:30118.1359
1704/10/2022 12:00136.4574
1714/10/2022 12:30119.0629
1724/10/2022 13:00105.0671
1734/10/2022 13:3093.29017
1744/10/2022 14:00117.4678
1754/10/2022 14:30130.3958
1764/10/2022 15:00130.6096
1774/10/2022 15:30125.786
1784/10/2022 16:00137.2079
1794/10/2022 16:30121.6497
1804/10/2022 17:00103.8545
1814/10/2022 17:30127.4414
1824/10/2022 18:00129.7855
1834/10/2022 18:30121.2626
1844/10/2022 19:00138.8651
1854/10/2022 19:30105.6053
1864/10/2022 20:00125.8709
1874/10/2022 20:30147.8033
1884/10/2022 21:00134.5637
1894/10/2022 21:30125.9159
1904/10/2022 22:0078.30851
1914/10/2022 22:3064.61543
1924/10/2022 23:0059.84072
1934/10/2022 23:3040.92291
Sheet1
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
I think this will do it. I only included a few rows.

You would be better off making the data into an Excel Table. This task could be done then with a Pivot Table, and PowerQuery would require the data to be in an Excel Table anyway.

MrExcel posts19.xlsx
ABCDEFGHIJK
1TimestampTotal Avg of Power (kW)DateTimePeriodDateDay5:30:00 AM6:00:01 PM
210/1/22 12:00 AM50.318941110/1/202212:00:00 AMNight10/1/202221.3489794
310/1/22 12:30 AM48.7355583310/1/202212:30:00 AMNight10/2/202220.8088817
410/1/22 1:00 AM41.7136861210/1/20221:00:00 AMNight10/3/202220.9934881
510/1/22 1:30 AM40.0466294510/1/20221:30:00 AMNight10/4/2022118.967566
610/1/22 2:00 AM46.6391905310/1/20222:00:00 AMNight
710/1/22 2:30 AM47.4582566710/1/20222:30:00 AMNight
810/1/22 3:00 AM51.3990472210/1/20223:00:00 AMNight
910/1/22 3:30 AM47.717945610/1/20223:30:00 AMNight
1010/1/22 4:00 AM24.1007516810/1/20224:00:00 AMNight
1110/1/22 4:30 AM22.7216450210/1/20224:30:00 AMNight
1210/1/22 5:00 AM25.507181110/1/20225:00:00 AMNight
1310/1/22 5:30 AM19.4705811310/1/20225:30:00 AMDay
1410/1/22 6:00 AM23.9777671810/1/20226:00:00 AMDay
Sheet38
Cell Formulas
RangeFormula
C2:C14C2=TRUNC(A2)
D2:D14D2=A2-C2
E2:E14E2=IF((D2>=$J$1)*(D2<=$K$1),"Day","Night")
G2:G5G2=UNIQUE(C2:C193)
H2:H5H2=AVERAGEIFS($B$2:$B$193,$C$2:$C$193,G2,$E$2:$E$193,$H$1)
Dynamic array formulas.
 
Upvote 0
Solution
Super! You're welcome.

Do notice the 6:00:01 pm thing. Excel is weird sometimes, and when the Excel DateTime Serial number is turned into a date and subtracted from it to get the time, it reports a value not exactly the same. Something to do with Excel precision of 14 digits. Whatever.
 
Upvote 0

Forum statistics

Threads
1,223,889
Messages
6,175,223
Members
452,620
Latest member
dsubash

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