IF, I understand (possibly I don't) the query then this solution will give a count of the 44 employees present during a given hour. I used a table populated with the formula:
=IF(ISNUMBER($B2),IF(ROUND($B2/(1/24),0)*(1/24)=ROUND(D$1/(1/24),0)*(1/24),"s",IF(ROUND($C2/(1/24),0)*(1/24)=ROUND(D$1/(1/24),0)*(1/24),"e",IF(OR(C2="d",C2="s",AND($B2>$C2,D$1<$C2)),"d",""))),"")
I then counted the values "s" and "d", assuming that an employee ends ("e") his/her shift at the beginning of the hour, using the formula:
=SUMPRODUCT((D$1:AA$1=AC2)*(D$2:AA$47="s"))+SUMPRODUCT((D$1:AA$1=AC2)*(D$2:AA$47="d"))
Here is a copy of your file with the table and formula applied: Copy of Libro1 (time ranges spanning midnight).xlsx
I imagine (hope even) that someone will post a one formula solution soon.
Let me know if you have any questions.
Bookmarks