Warm tip: This article is reproduced from stackoverflow.com, please click
arrays excel excel-formula

Excel maximum difference between consecutive values in array

发布于 2020-03-27 10:20:34

I have an array of numbers:

46.50, 46.50, 46.50, 50.00, 60.00, 57.00, 50.00, 48.00, 44.00, 42.00

I'd like to create a formula that finds the maximum positive difference between two consecutive pairs. So in the above example, the intermediate calculation would be:

0,0,-3.50,-10.00,3.00,7.00,2.00,4.00,2.00

Therefore the answer would be 7.00

Questioner
Anthony W
Viewed
191
Forward Ed 2019-07-04 04:45

Going to go with a basic array formula for this one. Aussuming your data is layed out as per the image below, used to offset ranges and subtract one range from the other. Then take the maximum of those results. This can be achieved using the following formula entered as an array. meaning you need to confirm it with CTRL+SHIFT+ENTER. You will know you have done it right when {} show up around your formula. They cannot be added manually.

=MAX(B3:B11-B4:B12)

as an alternative non array formula you can got with AGGREGATE which will perform array like calculations:

=AGGREGATE(14,6,B3:B11-B4:B12,1)

The above formulas will provide you with the largest positive difference. If how ever you need to know the largest difference, then -10 is a larger difference than 7. Its just in the opposite direction. To find this you would need to add ABS to the above equations as follows:

=MAX(ABS(B3:B11-B4:B12))

OR

=AGGREGATE(14,6,ABS(B3:B11-B4:B12),1)

POC