You can create a list state with 2 values: occupied or empty. Then every time an entity enters you set to occupied and when it leaves you check if it is the last entity and if so then set it to empty. The rest is taken for you and you can access percentage or total times easily.
Otherwise, you need to have 3 global variables, call them Sum, Aux (both Real) and and Occupied (Boolean) to keep track if occupied.
OnEntered: If not Occupied then Aux = TimeNow, Occupied = True.
OnExited: If Node.NumberTravelers == 0, then Sum = Sum + Aux - TimeNow, Occupied = False.
Paweł Kołodziejczyk | Systems Navigator