简体   繁体   中英

Excel maximum difference between consecutive values in array

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

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

Use an array formaula. If your values are in column A (rows 1 to 10 in this case), use

=MAX(A1:A9-A2:A10)

And enter it with CTRL-SHIFT-ENTER instead of just Enter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM