Oleg, Thank you so much for this! That was epic and worked completely. I did add a third condition where they had equal start and end time. I’m just going to put the evolution of this for those that it may help in the future as well as for myself if I ever need to come back to this in future.
What I wanted for this was check to see if a trainer is double booked in our schedule. In other words if they are supposed to be teaching two different groups of people at the same time. Because they physically can’t do that.
So to check for the if it was the same trainer I originally used
[Assigned To] = thisRow.[Assigned To]
which will work great if you only have one trainer/coach per session, but some of our sessions have multiple so if one session had Ryan and John and another had Ryan that will return a false, but I’m looking to see if Ryan was working either session so I had to change the formula to
[Assigned To].Contains(thisRow.[Assigned To])
Then I had to check to see if any events overlapped which @oleg helped me with! So I had this piece of the formula:
thisTable.Filter((thisRow.[Start Date and Time] > [Start Date and Time] AND thisRow.[Start Date and Time] < [End Date and Time]) OR (thisRow.[End Date and Time] > [Start Date and Time] AND thisRow.[End Date and Time] < [End Date and Time]))
Which helped a ton. The only thing I had to add that was to check for any events that started and ended at the same time bc the first two conditions were perfect for checking to make sure events didn’t overlap; bonus that it allowed for those that started at the same time as another ended (and vice versa) to pass the test because a trainer can end a class at 5 and start another at 5. So to check for that started and ended at the same time I added:
OR (thisRow.[Start Date and Time] = [Start Date and Time] AND thisRow.[End Date and Time] = [End Date and Time])
So you put it all together and you have:
thisTable.Filter([Assigned To].Contains(thisRow.[Assigned To]) AND ((thisRow.[Start Date and Time] > [Start Date and Time] AND thisRow.[Start Date and Time] < [End Date and Time]) OR (thisRow.[End Date and Time] > [Start Date and Time] AND thisRow.[End Date and Time] < [End Date and Time]) OR (thisRow.[Start Date and Time] = [Start Date and Time] AND thisRow.[End Date and Time] = [End Date and Time]))).Count()
It checks to see if someone is assigned to multiple events and if those events overlap and if so it returns a count. If the count is greater than 1 I am making it have a conditional formatting of red so that I or the scheduling manager knows that something is wrong with that event and to change who is assigned to it and that a conflict in time is present.
I also had to add another condition. I noticed that with the formula above if I did say an event that started at the same time as another and had a shared trainer, but the second event was actually a 2 hour event then it didn’t register as being overlapping and having the same trainer. This was because the second event’s start time was not greater than another’s, it’s end time was greater than another’s start time but not less than another’s end time, and it’s start and end times were not equal to another’s. So I had to add the opposite sequencing to check to see if another events start time was greater than this events start time and less than this events end time or if another events end time was greater than this events start time and less than this event’s end time (which was true in this case). So the final formula is:
thisTable.Filter([Assigned To].Contains(thisRow.[Assigned To]) AND (thisRow.[Start Date and Time] > [Start Date and Time] AND thisRow.[Start Date and Time] < [End Date and Time]) OR ([Start Date and Time] > thisRow.[Start Date and Time] AND [Start Date and Time] < thisRow.[End Date and Time]) OR (thisRow.[End Date and Time] > [Start Date and Time] AND thisRow.[End Date and Time] < [End Date and Time]) OR ([End Date and Time] > thisRow.[Start Date and Time] AND [End Date and Time] < thisRow.[End Date and Time]) OR (thisRow.[Start Date and Time] = [Start Date and Time] AND thisRow.[End Date and Time] = [End Date and Time])).Count()
Note: It did register for the shorter event so it would’ve been caught in the system for what I can see but I’d rather be safe than sorry and add these specific conditional cases to the formula to be sure.