Index + Match of the latest/max date value - google-sheets

I have a tab where there's multiple values for the same ID:
Date
ID
Column C
2021/11/23 9:02 PM
1427691673
2021-02-10
2021/11/24 9:02 PM
1427691673
2021-02-10
2021/11/25 9:02 PM
1427691673
2021-02-10
2021/11/26 9:01 PM
1427691673
2021-02-10
2021/11/27 9:01 PM
1427691673
2021-02-10
2021/11/28 9:02 PM
1427691673
2021-02-10
2021/11/29 9:02 PM
1427691673
2021-02-10
2021/11/30 9:02 PM
1427691673
2021-02-10
2021/12/1 9:02 PM
1427691673
2021-02-10
I would like to get the latest value for column C based on the latest date in column A. I have done something similar with Index + Match but I don't know how to filter it to get the MAX date.

Delete everything from Col C (including the header) and place the following formula in C1:
=ArrayFormula({"Header Text";IF(B2:B="",,VLOOKUP(B2:B,SORT({B2:B,A2:A},2,0),2,FALSE))})
You can change the "Header Text" label as desired within the formula itself.
Basically, this just looks up each ID in a virtual array sorted in reverse order by date. So the first match found will be the last date found.

Related

Extract date from text written timeslot

Trying to extract the date from the written string Thursday, Aug 25, 2022 2:00 PM-2:30 PM which should result in a date value of Thursday, Aug 25, 2022 2:00PM (or any date & time format).
Assuming the string is located in cell G2, I tried =TRIM(MID(G2,FIND(" ",G2),FIND(" ",G2,FIND(" ",G2)+1)-FIND(" ",G2))) and all I get is: Aug.
try:
=REGEXEXTRACT(A1, "\b[A-z]{3} \d+. \d+\b")

Google Sheets formula to convert FROM ordinal dates TO standard dates

I am looking for a formula that will automatically convert a column of ordinal date/time values into standard date/time values.
July 1st 2022 6:48:49 pm
July 2nd 2022 10:03:35 am
July 3rd 2022 5:41:12 pm
July 4th 2022 2:44:13 pm
I need to get those reformatted to eliminate the st, nd, rd, and th portions.
Sheet
You can use
=INDEX(IF(A2:A7="",, REGEXREPLACE(A2:A7,"st|nd|rd|th","")*1))
You can then format as you like
(Do adjust the formula according to your ranges and locale)
Functions used:
INDEX
IF
REGEXREPLACE

Regular Expression on IOS shortcuts for Line Matching

I'm trying to extract activities and the corresponding date and time from the list below. I'm using the shortcut app on iOS for the regex matching.
In the end I want to have the name of the activity and the time for the given weekday (parameter). Testing on https://regex101.com/
If you need more information let me know. Thanks in advance!
UPDATE:
Issue
So the issue is that with the current regex (see below) only activities are shown where the given weekday parameter is followed immediately. In the regex below it will only match
Pilates
Mittwoch 11:00 - 12:00
Mittwoch 17:00 - 18:00
Montag 19:00 - 20:00
Dienstag 17:00 - 18:00
Dienstag 18:00 - 19:00
Donnerstag 11:00 - 12:00
Donnerstag 17:00 - 18:00
Donnerstag 20:00 - 21:00
Freitag 17:00 - 18:00
Samstag 11:00 - 12:00
Samstag 13:00 - 14:00
Sonntag 12:00 - 13:00
Example Code
Mittwoch (Wednesday) added as example, this will be a dynamic variable in the end.
([-\&\sA-zÀ-ÿ]+\n((Mittwoch)\s\d+:\d+\s-\s\d+:\d+\n)+)
Example data
Pilates
Montag 19:00 - 20:00
Dienstag 17:00 - 18:00
Dienstag 18:00 - 19:00
Mittwoch 11:00 - 12:00
Mittwoch 17:00 - 18:00
Donnerstag 11:00 - 12:00
Donnerstag 17:00 - 18:00
Donnerstag 20:00 - 21:00
Freitag 17:00 - 18:00
Samstag 11:00 - 12:00
Samstag 13:00 - 14:00
Sonntag 12:00 - 13:00
Expected Result
Pilates
Mittwoch 11:00 - 12:00
Mittwoch 17:00 - 18:00
Try this Regex.
The regular expression that I use it is this one. Matching only if the name of activitiy is Pilates.
(Pilates\s*)|(Mittwoch [012]\d:[0-5]\d - [012]\d:[0-5]\d\s*)
If the name of the activity is a set of characters then, try this one.
^(\w+\s\s)|(Mittwoch [012]\d:[0-5]\d - [012]\d:[0-5]\d\s*)
As you say, the parameter for this example is Mittwoch, you can change it as your needs.
Hope this help you.

Lookup Current Day and Time with QUERY or VLOOKUP

I currently pull in some appointment time slots based on the current time now() and extract the timeslots from the adjacent worksheet.
I now want to add in the current day of the week as an argument as well. Would I need to do something more advanced like =query or how could I extend this to the current =vlookup?
Here are what I got so far with QUERY and VLOOKUP:
=query(TimeSlots!C2:F25, select 2,3,4,5 where Col1 = Live!A2 & where Col2 = Live!B2)
=vlookup(timevalue(B2), {iferror(value(regexextract(TimeSlots!B2:B, "(.+)\s-"))),TimeSlots!C2:F}, {2, 3, 4, 5}, 1))
https://docs.google.com/spreadsheets/d/1OOdLI-1j3d10LsfGdNPS4tOusx4AnRZvXzdgmrLvrSA/edit?usp=sharing
If you want to have a play and Make a Copy, here links.
I write this in good faith with your success at heart; things are a bit more difficult for you than they need be because you are breaking a couple of the unwritten rules of spreadsheet normalization. Most prominently, if you wish to use a cell in a formula elsewhere, the cell should be in a Sheets-native format. Try this:
Select TimeSlots column B
From the menus, choose Insert → Column Right
Rename B and C to, say… "Time Slot Begin" and "Time Slot End", respectively
Edit the data to recreate your ranges in this new split arrangement (included below if you want to copy-paste)
Armed with uniform, natively-calculable data sources, you can now use a formula to get the row(s) where the weekdays match and the current time is greater than the slot's start time and the current time is less than the slot's end time.
For example:
=FILTER( TimeSlots!A2:G29,
A$2 = TimeSlots!A2:A29,
MOD(B$2,1) > TimeSlots!B2:B29,
MOD(B$2,1) < TimeSlots!C2:C29
)
Line by line, in English, it: narrows down the list of Time Slots to rows where
this sheet's day matches the TimeSlot's day, and
this sheet's time is after (greater than) the Time Slot's beginning, and
this sheet's time is before (less than) the Time Slot's ending.
Note that NOW() outputs a datetime, of which you are showing just the time using "cosmetic" formatting. To only look at the actual time component of the B2 date-time, I'm dividing by 1 day and keeping the remainder time.
Here are the aforementioned columns of time starts and ends, if you want to paste them into place. Column B:
Time Slot Begin
07:00:00
09:00:00
16:00:00
20:00:00
07:00:00
09:00:00
16:00:00
20:00:00
07:00:00
09:00:00
16:00:00
20:00:00
07:00:00
09:00:00
16:00:00
20:00:00
07:00:00
09:00:00
16:00:00
20:00:00
07:00:00
09:00:00
16:00:00
20:00:00
07:00:00
09:00:00
16:00:00
20:00:00
and Column C:
Time Slot End
08:59:00
15:59:00
19:59:00
06:59:00
08:59:00
15:59:00
19:59:00
06:59:00
08:59:00
15:59:00
19:59:00
06:59:00
08:59:00
15:59:00
19:59:00
06:59:00
08:59:00
15:59:00
19:59:00
06:59:00
08:59:00
15:59:00
19:59:00
06:59:00
08:59:00
15:59:00
19:59:00
06:59:00

Get list of weeks that start on a Friday

I want to count the number of the weeks, starting from Friday.
For more explanation: usually the counting starts on Sunday or Monday, but in this case, I want to make it start on Friday.
Some examples:
2nd Jan 2015 (Fri) ~ 8th Jan 2015 (Thu) : 1st week of 2015
...
25th Dec 2015 (Fri) ~ 31st Dec 2015 (Thu) : 52nd week of 2015
1st Jan 2016 (Fri) ~ 7th Jan 2016 (Thu) : 1st week of 2016
...
30th Dec 2016 (Fri) ~ 5th Jan 2017 (Thu) : 53rd week of 2016
6th Jan 2017 (Fri) ~ 12th Jan 2017 (Thu) : 1st week of 2017
What I need to do is
1) to get the week number from the date
ex.
input: Fri, 02 Jan 2015
output: 1
input: Sun, 27 Dec 2015
output: 52
2) to get the date range for the given week number.
I found that .strftime("%V") does almost this, but it counts weeks by every Monday.
Does anyone know nice solution to this?
Here you go:
my_array = Array.new
(Date.today..Date.today.next_year).each do |date|
if date.wday == 5
end_week = date + 6.days
my_array << "#{date.day.ordinalize} #{date.strftime('%b')} #{date.strftime('%Y')} (#{date.strftime('%a')}) ~ #{end_week.day.ordinalize} #{end_week.strftime('%b')} #{end_week.strftime('%Y')} (#{end_week.strftime('%a')}) : #{date.strftime('%U')} week of #{date.strftime('%Y')}"
end
end
# sample output of first element of array
# 30th Oct 2015 (Fri) ~ 5th Nov 2015 (Thu) : 43 week of 2015
Note: You can set any range. here I have set from Today to next year
%U - Week number of the current year, starting with the first Sunday
as the first day of the first week (00..53)
%W - Week number of the current year, starting with the first Monday
as the firstday of the first week (00..53)
for more info: http://apidock.com/rails/ActiveSupport/TimeWithZone/strftime
You can do the variety of operation on the dates here...
DateAndTime
In your case, the below will work for you.
all_week(start_day = Date.beginning_of_week)

Resources