You are trying to only count the no. of unique values rite? Then you can try
Formula: copy to clipboard
=sumproduct(1/countif(Range,Range))


If you tell the criteria in A, B and O column, i can expand the formula further.