Select “Time Description” based on current date and time in Google Sheets (VLookup, Query)

前端 未结 2 1317
走了就别回头了
走了就别回头了 2021-01-22 16:38

I am trying to use VLookup or QUERY to extract a day and time description based on the current date and time. I thought QUERY may be the b

2条回答
  •  庸人自扰
    2021-01-22 17:26

    based on your time data logic try:

    =ARRAYFORMULA(IFERROR(TEXT(A2:A, "ffffdd ")&VLOOKUP(TIMEVALUE(A2:A), {
     TIMEVALUE("00:00"), "Evening";
     TIMEVALUE("07:00"), "Breakfast";
     TIMEVALUE("09:00"), "Morning";
     TIMEVALUE("16:00"), "Daytime";
     TIMEVALUE("20:00"), "Evening"}, 2, 1)))
    


    for non-hardcoded references use:

    =ARRAYFORMULA(IFERROR(TEXT(A2:A, "ffffdd ")&VLOOKUP(TIMEVALUE(A2:A), 
     SORT({TIMEVALUE(REGEXEXTRACT(TimeDescription!A2:A, "(.*) -")), 
     TimeDescription!B2:B}, 1, 1), 2, 1)))
    

    spreadsheet demo

提交回复
热议问题