In Excel, Find the Maximum Value and the Neighboring N Members Before and After

In Excel, Find the Maximum Value and the Neighboring N Members Before and After

Problem description & analysis:

The column below contains numeric values only:

A
113
221
346
421
549
69
734
823
96
101
1137
1249
1342
1440
1515
1631
1717
181147
1918
2030
2122
224
2325
2419
2513
2627
2738
2830
2916
3012
3123
323
3323
3419
3514
3646
3723
3837
3938
4028

We need to find out the maximum value and the 10 neighboring members both before and after it. Remember to perform out of bounds check as it is possible that the actual number of eligible values is less than 10.

A
123
26
31
437
549
642
740
815
931
1017
111147
1218
1330
1422
154
1625
1719
1813
1927
2038
2130

Solution:

Use SPL XLL to enter the formula below:

=spl("=p=(d=?).pmax(),d.calc(p,~[-10:10])",A1:A40)

Picture1png

Explanation:

pmax()function gets the position of the maximum value. calc() function performs the computation according to the specified positions; ~ represents the current member, and [] gets members according to the interval specified by the relative positions, which automatically prevents the array index out of bounds.

esProc Desktop is now FREE to download. Please do not hesitate to try it by yourself! http://www.scudata.com/download-Desktop