I have a formula to write in Excel that is supposed to check whether any given/entered date falls in one of multiple given time periods, where said time periods are given as "starting date" and "end date", where the "end date" is obviously required to be after the "start date" (or is the same).
Think of it as a check, whether on a date any colleague is on vacation, the time periods being the vacation times.
Now, for only ONE period in my list of periods, this is a no brainer:
=IF(AND(A1>=B1;A1<=C1);TRUE;FALSE)
(assuming that I enter the date to check in A1 and define periods start/end times in B1/C1 respectively)
Now, for a list of said time periods, I would want to resort to using SQL. Anyhow, is there a nice and easy trick to get this working without too much fuss?
Mock data:
| A | B | C | |
|---|---|---|---|
| 1 | 1.5.23 | 30.4.23 | 2.5.23 |
| 2 | 7.7.23 | 7.7.23 |
(European date format)
The value of A1 lies in the period defined in B1/C1, but not in period B2/C2. The formula should return "true"
>Solution :
Use SUMPRODUCT:
=SUMPRODUCT((A1>=E1:E2)*(A1<=F1:F2))>0
