Try: =MEDIAN(IF(B1:B1000=1,A1:A1000))

Confirmed with Ctrl+Shift+Enter rather than just Enter as it's an array formula.

Dom