Home > Software design >  How to check for overlapping dates
How to check for overlapping dates

Time:01-18

I am looking for a solution on either Google sheets or app script to check for overlapping dates for the same account. There will be multiple accounts and the dates won't be in any particular order. Here is an example below. I am trying to achieve the right column "check" with some formula or automation. Any suggestions would be greatly appreciated.

Start Date End Date Account No. Check
2023-01-01 2023-01-02 123 ERROR
2023-01-02 2023-01-05 123 ERROR
2023-02-25 2023-02-27 456 OK
2023-01-11 2023-01-12 456 OK
2023-01-01 2023-01-15 789 ERROR
2023-01-04 2023-01-07 789 ERROR
2023-01-01 2023-01-10 012 OK
2023-01-15 2023-01-20 012 OK

I also found some similar past questions, but they don't have the "for the same account" component and/or requires some sort of chronological order, which my sheet will not have.

enter image description here

(2) Here is the method using the enter image description here

(3) Most efficient is to use the original method of comparing previous and next dates, but then you need to sort and sort back like this:

=lambda(data,sort(map(sequence(rows(data)),lambda(c,if(if(c=1,0,(index(data,c-1,2)>=index(data,c,1))*(index(data,c-1,3)=index(data,c,3))) if(c=rows(data),0,(index(data,c 1,1)<=index(data,c,2))*(index(data,c 1,3)=index(data,c,3)))>0,"ERROR","OK"))),index(data,0,4),1))(SORT(filter({A2:C,row(A2:A)},A2:A<>""),3,1,1,1))
  • Related