Calculated fields with clauses

I am setting up sugarCRM for a real estate administration company..

I have used the accounts module for buildings and apartments..
Each apartment is a member of the building they are in..

I have made a calculated field (count($members)) to show how many apartments fall under one building.. (this works)

Each apartment has a status field (dropdown) that is either 'Rented' or 'Available', I would like to count how many apartments are rented in each building.

In SQL it would look something like this:
SELECT *
FROM Building1
WHERE status = 'Rented'

How do I make this in sugar?