Assuming (from before) that the data is unsorted the quickest approach is to concatenate the two columns of interest enabling you to conduct a quick COUNTIF test against the concatenation column... else you will need to use an approach along the lines of:
=IF(ISNUMBER(LOOKUP(2,1/((rangeA=valueA)*(rangeB=valueB)))),MEDIAN(IF(...)),"")
This will still be quicker than conducting all of the arrays you're presently conducting but not as fast as it could be... you could if preferred even ensure you only insert formulae into the relevant cells... ie:
Bookmarks