I only noticed now that you tagged Excel 2007:
You may want to use this for that version:
=SUM(--ISNUMBER(MATCH(B2:B10&F3,A2:A10&F3,0)))
=SUM(ISNA(MATCH(B2:B10&C2:C10,A2:A10&C2:C10,0))*(C2:C10=F2))-1
!! Note that both formulas require being entered with ctrl+shift+enter
The first returns the number of results where the Room in column C equals the value in F3
where the Date Out value is also found in the Date In column where the room equals F3
.
The second returns the number where the Date In value doesn't equal the Date out value doesn't equal where the room equals F3
. But since there's always a last value that doesn't have a later date; we subtract 1 of the summed total.
If you use Office 365 you could achieve the following:
Maybe my answer is not in the format you requested, but I think this may be giving you more insight:
=LET(sorted,SORT(A2:C10,{3,2}),
room,TAKE(sorted,,-1),
roomcomp,(DROP(room,-1)=DROP(room,1)),
indate,DROP(TAKE(sorted,,1),1),
outdate,DROP(INDEX(sorted,,2),-1),
VSTACK(HSTACK(A1:C1,
"next date in "&{"=",">"}&" previous date out"),
IFERROR(HSTACK(sorted,
(roomcomp)*(outdate=indate),
(roomcomp)*(outdate<indate)),
"")))
It will show the same range, but sorted by Room, then date out and the result by row for the next indate being equal to or greater than the previous outdate. That way you also see for which date(s) the conditions apply.
![enter image description here](https://cdn.statically.io/img/i.sstatic.net/EeTWN.png)
Basically what it does is =(B2:B9=A3:A10)*(C2:C9=C3:C10)
and =(B2:B9<A3:A10)*(C2:C9=C3:C10)
but on the Range B2:C10 sorted by Room then by Date (out).
Another way of creating more insight is to show the last day out where the day in and day out are consecutive for the same room:
=LET(a,A2:A10,b,B2:B10,c,C2:C10,r,SEQUENCE(ROWS(a)),MAP(a,b,c,LAMBDA(u,v,w,REDUCE(v,r,LAMBDA(x,y,XLOOKUP(x&w,a&w,b,x))))))
![enter image description here](https://cdn.statically.io/img/i.sstatic.net/eOBGY.png)