How to signal out an overlap among date ranges - google-sheets

Have no idea how to solve the following problem:
In a given sheet where column "A" is the starting date (month/day/year), "B" is the ending date and "C" is the description, any date range overlap among rows should be signaled out in column "D".
The resulting table should look like this:
#
A
B
C
D
1
01/01/2022
02/01/2022
Task1
Row3
2
01/15/2022
02/15/2022
Task2
3
01/29/2022
02/03/2022
Task1
Row1, Row3
4
01/18/2022
02/22/2022
Task3
5
02/02/2022
02/15/2022
Task1
Row3
Link to the sheet

If the dates cross over IF(($A1<=$B$1:$B$5)*($B1>=$A$1:$A$5)
and if the Task is the same ($C1=$C$1:$C$5)
but not if the row is the same IF(ROW($A$1:$A$5)=ROW(),""
then return the Row # "Row"&ROW($A$1:$A$5)
Complete formula:
=ARRAYFORMULA(TEXTJOIN(", ",TRUE,IF(($A1<=$B$1:$B$5)*($B1>=$A$1:$A$5)*($C1=$C$1:$C$5),IF(ROW($A$1:$A$5)=ROW(),"","Row"&ROW($A$1:$A$5)),"")))

Related

Formula to build report of employees that are not working between 2 dates

I am trying to find a way to see which employees are not working between 2 dates.
Should I use vlookup, index & match, filter, query, or something else?
Sheet 1 contains employee details & start/end dates.
Sheet 2 accepts user input to select 2 dates, and it will automatically display a list of available employees who are not working.
Sheet 1 - Database/Log of all employees and days worked.
#
A
B
C
D
1
ID
Name
Start Date
End Date
2
12345
John
01/01/2021
01/08/2021
3
54321
Sarah
01/24/2021
01/29/2021
4
00731
James
02/05/2021
02/15/2021
5
00731
John
02/10/2021
02/30/2021
Sheet 2 (Row 1-2)- Manually enter in two dates.
#
A
B
1
Start Date (Manual input)
End Date (Manual input)
2
01/01/2021
01/30/2021
Sheet 2 (Row 3+)- List of all employees that are not working between the two dates entered in Sheet 2!A2:B2 (Expected Results)
#
A
B
3
ID
Name
4
00731
James
try:
=INDEX(SUBSTITUTE(UNIQUE(QUERY(""&SPLIT(FLATTEN(IF(SEQUENCE(1, MAX(D2:D-C2:C))<=D2:D-C2:C,
"♥"&A2:A&"♦"&B2:B&"♦"&C2:C+SEQUENCE(1, MAX(D2:D-C2:C), 0), )), "♦"),
"select Col1,Col2 where not Col3 matches '"&JOIN("|", "^$",
IF(SEQUENCE(1, G2-F2)<=G2-F2, F2+SEQUENCE(1, G2-F2, 0), ))&"'", 0)), "♥", ))
demo sheet
Assuming the name of your first sheet with the full data is actually Sheet1, place the following in Sheet2 cell A4:
=FILTER(Sheet1!A2:B,Sheet1!A2:A<>"",(Sheet1!C2:C>G2)+(Sheet1!D2:D<F2))
The combined either/or condition (Sheet1!C2:C>G2)+(Sheet1!D2:D<F2) in the FILTER means "either the start date is after the range date given, or the end date is before the range date given."
The other condition of Sheet1!A2:A<>"" just rules out blank rows in the original data set. It's not strictly necessary as far as the visual results are concerned; but it keeps null rows from being added to those results, which would allow you to enter data below the results in Col A and B of Sheet2 if you wanted, or to have fewer rows in Sheet2 than in Sheet1 without the formula adding more rows to accommodate null returns.
Your posted sample data is unclear. You have two different names for the same ID (i.e., 00731). And you have an "End Date" in D5 of February 30, 2021—which is not a valid date. In any case, it's unclear whether the same person/ID may turn up twice in the original data set. My formula above assumes you will not.
If your original data list may, in fact, contain duplicates, things get a bit trickier. In that case, use the following formula instead, in Sheet2 cell A4:
=UNIQUE(FILTER(A2:B,ISERROR(VLOOKUP(A2:A,FILTER(A2:A,((C2:C>=F2)*(C2:C<=G2))+((D2:D>=F2)*(D2:D<=G2))),1,FALSE))))
Here, the inner FILTER first forms a list of all people who are working during that range, and then the outer FILTER filters in a UNIQUE set of the people who are not on that inner list (i.e., trying to VLOOKUP them returns IS(an)ERROR).

Google Sheets Lookup Row and Get Last Value

I have a Google Sheet with two sheets in it.
The first sheet is a list of songs with Title, Library #, Composer, ..., Last Performance Date
The second sheet is a list of performance dates with Title, Library #, date 1, date 2, ..., date n
Sheet 1 Example:
Title, Library #, Composer, Last Performance Date
Hip Song 1007 David {formula}
Slow Song 1002 Bob {formula}
Other Song 1004 David {formula}
Sheet 2 Example:
Title, Library #, Dates ->
Slow Song 1002 2021-01-12 2021-02-15
Other Song 1004
Hip Song 1007 2021-01-05
How can I automatically fill in the "Last Performance Date" column on the first sheet by looking up the song on the second sheet by the "Library #" and getting the last value in that row (with a variable number of dates per song on the second sheet).
With the example above, the Last Performance Date for "Hip Song" would be "2021-01-05", "Slow Song" would be "2021-02-15", and "Other Song" would be "" (an empty string or nothing).
For any given song, there could be no dates on the second sheet or a 100+ dates on that song's row.
I'd add a helper column to Sheet2 that contains the formula that calculates the "latest" date for a given song:
Sheet2
A
B
C
D
E
1
Title
Library #
Latest Date
Dates
2
Slow Song
1002
=IF(MAX(D2:E2)=0,"",MAX(D2:E2))
2021-01-12
2021-02-15
3
Other Song
1004
=IF(MAX(D3:E3)=0,"",MAX(D3:E3))
4
Hip Song
1007
=IF(MAX(D4:E4)=0,"",MAX(D4:E4))
2021-01-05
The IF(X=0,"",X) part of the formula is so that songs that don't have any dates show up as blank instead of 0 (which will get formatted as 1899-12-30).
Then, in Sheet1, use the VLOOKUP function to find the matching "latest date":
Sheet1
A
B
C
D
1
Title
Library #
Composer
Last Performance Date
2
Hip Song
1007
David
=VLOOKUP(B2,Sheet2!$B$2:$C$4,2,FALSE)
3
Slow Song
1002
Bob
=VLOOKUP(B3,Sheet2!$B$2:$C$4,2,FALSE)
4
Other Song
1004
David
=VLOOKUP(B4,Sheet2!$B$2:$C$4,2,FALSE)
Note the FALSE as the last parameter to VLOOKUP, which makes sure it will still return correct results, even if the data in Sheet2 is not sorted by Library #.
See this example spreadsheet.
if your dates (if present) are increasing with each next column try:
=INDEX(IF(B2:B="",,IFERROR(1*SPLIT(FLATTEN(QUERY(TRANSPOSE(IFNA(VLOOKUP(B2:B, Sheet2!B1:1000,
TRANSPOSE(SORT(SEQUENCE(COLUMNS(Sheet2!C1:1))+1, 1, 0))), 0)),,9^9)), " "))),,1)
demo spreadsheet
fx transcript: count columns from column with 1st date and create a sequence of number with +1 offset for each number. then sort the sequence in descending order and transpose it into row - this will be the 3rd parameter of vlookup which will return date columns in reverse order eg.: ..., Col5, Col4, Col3, Col2. so in vlookup we look for B2:B values in range Sheet2:B1:1000 and return multiple columns on each match. next, we transpose all results of vlookup and with query parameter ,,9^9 we collapse all rows of each column into a single row. next, we flatten the results and split by empty space (which was inserted after each date via query). in this stage, column with the latest date became our 1st column. next, dates are numeric values so we multiply them by 1 to catch errors of those cells that have no date only empty spaces. at last, we use simple if statement to check if B2:B range is empty. if so we return no value, otherwise we return date. and to limit the output only to 1 single column we use index to return all rows but only the first column

Google Sheets how to get value on certain row if the column is Today()?

I have these sheets on Google Sheets
Sheet "Alpha"
A B C D
1 Date 03/11 03/12 03/13
2 Status DONE DONE In Risk
Sheet "Beta"
A B C D
1 Date 03/11 03/12 03/13
2 Status DONE DONE DONE
Sheet "Gamma"
A B C D
1 Date 03/11 03/12 03/13
2 Status DONE In Risk BLOCKED
I want to make a summary sheet with result on daily based as below:
Let's suppose today is 03/13
Sheet "Summary"
A B
1 Name Status
2 Alpha In Risk
3 Beta DONE
4 Gamma BLOCKED
I want to populate the column A using script or function.
So, the step on my mind would be:
Populate column A with script/function
On column B using formula for:
Finding the Today date on other sheet
Get value of the row on the column from today date from other sheer
Is it possible to do? How to do it?
In Sheet "Summary"
Finding by name in Column A
Cell B2: =HLOOKUP(TODAY(),INDIRECT(A2&"!$1:$2"),2,0)
Cell B3: =HLOOKUP(TODAY(),INDIRECT(A3&"!$1:$2"),2,0)
Cell B4: =HLOOKUP(TODAY(),INDIRECT(A4&"!$1:$2"),2,0)
Finding by Sheet
Cell B2: =HLOOKUP(TODAY(),Alpha!$1:$2,2,0)
Cell B3: =HLOOKUP(TODAY(),Beta!$1:$2,2,0)
Cell B4: =HLOOKUP(TODAY(),Gamma!$1:$2,2,0)
Function References
HLOOKUP

Counting recent visits based on date range

I have one column with Name.
I have a 2nd column with Date associated with a visit.
I wanted to generate a count of how many times the person has visited in a previous number of days.
If the number is greater than X, I want to fill another column with match.
I'm having trouble figuring out how to filter out names that don't match the row, while simultaneously counting how many times that person has dates that fall within the 7 day range.
So if John visited on 1/23, 2/4, 2/6, and 2/8, and the range is 7 days, it should add "3" to the "recent visits" column next to John's 2/8 row, fill 2 into the "recent visits" column for 2/6, and 1 for 2/4 and 1/23.
There will be other rows with other names that will have the same requirements, so it would also need to filter out names that don't match John.
What I'm trying to do with this, is trigger an alert through Zapier to send an email when there is a frequent visitor match.
cell C2: =UNIQUE(FILTER(A2:A, A2:A<>""))
cell D2:
=COUNTA(QUERY(ARRAYFORMULA($A$2:$B),
"select A where B >= date '"&TEXT(TODAY()-7, "yyyy-mm-dd")&"'
and B <= date '"&TEXT(TODAY(), "yyyy-mm-dd")&"'
and A = '"&C3&"'", 0))
and drag down from D2 cell

Query values from separate sheet

I am trying to figure out how to query values from Sheet2 into Sheet1 where column A in Sheet1 matches column A (strings) in Sheet2, and return only the max value of column D (integer) from Sheet2.
Here's what I am using:
=Query(Sheet2!A:F,CONCATENATE("Select D where Name =",A2))
I have tried using Select max(d)... and =MAX(Query(...)) but neither worked for me.
What would be the correct way to do this?
Example data:
Sheet1
Name ColB Date Check Oldest
Bob Y 2/14/2013 4/14/2013 5
Sheet2
Name Title Date Age
Bob Foo 2/1/2013 3
Boo Bar 2/4/2013 5
This may serve, if entered in the cell presently containing Oldest (which would then be overwritten with max Age:
=query(Sheet2!A:D,"select max(D) where A ='Bob' ")
but the result for your sample would be 3 rather than the 5 as shown to be required.

Resources