I am trying to calculate Mode based on two criteria. If there is no mode, i.e., there is only single occurrence of the criteria my results are correct. However, when there are two mode values, the formula results in the first mode. Any idea what am I doing wrong?

This picture shows the correct results

This is where I have a problem. Excel is picking the first mode value

Column C is the calculated value which is incorrect for my exercise. Column D is what I like to get.

What modifications do I need to my formula to get the desired results?

Any help is greatly appreciated.