Pergunta

I have data with two columns A and B. I need a formula to find the value in column B which is closest to a input value where the corresponding value in column A equals a second input value.

For example, here is some sample data

Col A   Col B
12.5    0.4
12.5    0.69
12.5    0.75
18      0.5
18      0.695
18      0.4
20      0.2
20      0.8
20      0.71

Let's say my input value for A is 12.5 and my input value for B is 0.7. The formula would return the value 0.69 because that is the number which is closest to 0.7 in the subset of data where Col A equals 12.5.

If I change input A to 18 and leave input B to 0.7 the formula should return 0.695.

For an input of A = 20 and B = 0.7 the formula would return 0.71

Is this making sense?

I know the following formula can be used to find a value closest to another value.

=INDEX(rng,MATCH(MIN(ABS(rng-value)),ABS(rng-value),0))

And I know you can use SUMPRODUCT to search on multiple criteria. I just can't figure out how to put it all together.

Foi útil?

Solução

Let your values are in A1:B9, then use:

=INDEX(B1:B9,MATCH(MIN(ABS(IF(A1:A9=12.5,B1:B9)-0.7)),ABS(IF(A1:A9=12.5,B1:B9)-0.7),0))

This is an array formula, so type the formula then press CTRL+SHIFT+ENTER. Curly brackets will automatically appear at the start and end of the formula.

Or another approach (returns min from closest):

=MIN(IF(MIN(ABS(IF(A1:A9=12.5,B1:B9)-0.7))=ABS(IF(A1:A9=12.5,B1:B9)-0.7),B1:B9))

also with array entry (CTRL+SHIFT+ENTER)

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top