Excel: Find min/max values in a column among those matched from another column

爷,独闯天下 提交于 2019-11-27 15:37:55
Dmitry Pavliv

It works for me.

for min:

=MIN(IF(($A$1:$A$50=D1),($B$1:$B$50)))

for max:

=MAX(IF(($A$1:$A$50=D1),($B$1:$B$50)))

Note, that it is an array formulas, so you need to press CTRL+SHIFT+ENTER

You can use array formulas to give you the answers you need.

For the min you can use the formula in cell E1:

{=MIN(IF($A:$A=D1,$B:$B))}

and the max the formula for cell F1 is :

{=MAX(IF($A:$A=D1,$B:$B))}

To enter an array formula, you should enter everything except the braces (the curly brackets) then press the Ctrl and Shift keys when you press the enter key... this will add the braces and the formula will be considered an array formula.

Once entered, you can copy the formula down for the other matched values

Array formulas work by calculating every combination. It will calculate if the value in A1 is the same as D1, and if it is it will give the value of B1, then if the value of A2 is the same as D1 it will give the value of B2, and so on. This will give you a list (or array) of values from the B column where the value in A is a match. The MIN/MAX is then calculated as normal.

The INDEX function can help you avoid CSE by building a standard formula using some math to either zero or make astronomical any non-matching values depending upon whether you are looking for a MAX or MIN result.

The pseudo-MAXIF formula is a little easier so I'll start there.

=MAX(INDEX(B:B*(A:A=D1), , ))

Excel treats any boolean TRUE statement as 1 and any FALSE as 0 when used mathematically. Multiplying a value in column B by 1 leaves the value unchanged; multiplying by 0 will result in zero. The INDEX function passes an array of unchanged values and zeroes into the MAX function depending upon whether that match the criteria or not. The result will be the maximum value from column B where column A is equal to the criteria.

The pseudo-MINIF formula essentially flips the process around by mathematically excluding any non-matching value, leaving only matching values from which to choose a MIN from.

=MIN(INDEX(B:B+(A:A<>D1)*1E+99, , ))

Again, TRUE is 1 and FALSE is 0 but this time we are using it to add 1E+99 (a 1 followed by 99 zeroes which isn't going to be the MIN of anything) to any non-matching values. Matching values will have 0 × 1E+99 added to them which equates to zero and will not change their value.

             

The full column cell range references I've used do not negatively impact calculation lag any more than a similar array formula would.

You can have the references calculate themselves, assuming there are no gaps in the data, using named ranges.
e.g.

ARange =OFFSET($A$2,0,0,COUNT($A:$A))
BRange =OFFSET($B$2,0,0,COUNT($A:$A))

(I use the same COUNT in both to ensure the areas are the same size)

Now I can use an array formula =MAX((ARange=D2)*(BRange)) to get the max (and same for min).
Array Formulas are entered with CTRL+SHIFT+Enter

See @Simoco's answer for the correct formula

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!