Google-sheets – Min/Max of a row only if value in other row is X

google sheets

I'm a bit vague as to what I am looking for/asking about, but here is an example:

A  | B
22 | 5
15 | 5
2  | 10
19 | 10
5  | 10


=min(A2:A6, if(B2:B6=5, 5)) ==> 15
=min(A2:A6, if(B2:B6=5, 10)) ==> 2

Given a large range (1000+ rows), it only includes in the calculation (which may be min/max/avg) the cells if another cell in the same row contains a particular value.

Best Answer

I believe this is what you're looking for:

=ARRAYFORMULA(min(if(B2:B6=5,A2:A6)))

The full documentation for arrayformula is at Google Support. "This function allows the specification of a range (or multiple ranges of the same size) in functions that don't normally accept ranges."