Apr 16 2019 01:48 AM
Hi,
I would like to be able to identify which cells have the time which is closest to 07:00 on any given day. Does anyone know how this might be done?
Please see the attached image to illustrate what I mean. The cells in orange are the ones with the time closest to 07:00.
Any help would be much appreciated.
Thanks,
Martin
Apr 16 2019 02:27 AM
Apr 16 2019 02:35 AM
Many thanks @Jan Karel Pieterse,for the feedback, unfortunately that will not help because if the datetime range were different, it is possible that the times could be before 06:00 or after 08:00.
Here is another example to show you what I mean:
Apr 16 2019 03:27 AM
Solution@martin77 , for such sample
it could be
=A2=IF(INT(A2)+7/24-AGGREGATE(14,6,1/(INT(A2)+7/24>$A$2:$A$26)*$A$2:$A$26,1)< AGGREGATE(15,6,1/(INT(A2)+7/24<=$A$2:$A$26)*$A$2:$A$26,1)-(INT(A2)+7/24), AGGREGATE(14,6,1/(INT(A2)+7/24>$A$2:$A$26)*$A$2:$A$26,1), AGGREGATE(15,6,1/(INT(A2)+7/24<=$A$2:$A$26)*$A$2:$A$26,1))
Apr 16 2019 03:44 AM
Wow@Sergei Baklan - That is amazing. :)
Thanks you so much for your help. I am now going to investigate what you have done here as I am not yet familiar with the 'aggregate' formula.
Apr 16 2019 04:03 AM
Hi Martin,
AGGREGATE finds largest (first parameter 14) or smallest (15) value in the array (third parameter) ignoring all errors (second parameter = 6). Array is multiplication of 1/(...), which gives ignored error if time is more than/less than 7am for given date, on dates itself. Thus first part gives error or 1, multiplied on the date it returns error or date.
Finding closest early time and closest later time we compare it, and depends on where the difference is less take one or another.
What I forgot that's to test if you have exactly 7:00 in your date/time, perhaps we shall use <= (or >=) in one of conditions instead of < or > (AGGREGATE will return exact date in both cases)
Apr 16 2019 04:26 AM
I'll test if it falls at 07:00 and will study the formula.
Thanks again, you are a legend @Sergei Baklan
Apr 16 2019 07:11 AM
@martin77 , thank you, you are welcome
Apr 16 2019 03:27 AM
Solution@martin77 , for such sample
it could be
=A2=IF(INT(A2)+7/24-AGGREGATE(14,6,1/(INT(A2)+7/24>$A$2:$A$26)*$A$2:$A$26,1)< AGGREGATE(15,6,1/(INT(A2)+7/24<=$A$2:$A$26)*$A$2:$A$26,1)-(INT(A2)+7/24), AGGREGATE(14,6,1/(INT(A2)+7/24>$A$2:$A$26)*$A$2:$A$26,1), AGGREGATE(15,6,1/(INT(A2)+7/24<=$A$2:$A$26)*$A$2:$A$26,1))