Use SUMPRODUCT() instead of SUM() and IF(). This gives you the opportunity to sum on multiple criteria.