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
1 13
2 21
3 46
4 21
5 49
6 9
7 34
8 23
9 6
10 1
11 37
12 49
13 42
14 40
15 15
16 31
17 17
18 1147
19 18
20 30
21 22
22 4
23 25
24 19
25 13
26 27
27 38
28 30
29 1…


This content originally appeared on DEV Community and was authored by Judith-Excel-Sharing

Problem description & analysis:
The column below contains numeric values only:

   A
1 13
2 21
3 46
4 21
5 49
6 9
7 34
8 23
9 6
10 1
11 37
12 49
13 42
14 40
15 15
16 31
17 17
18 1147
19 18
20 30
21 22
22 4
23 25
24 19
25 13
26 27
27 38
28 30
29 16
30 12
31 23
32 3
33 23
34 19
35 14
36 46
37 23
38 37
39 38
40 28

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
1 23
2 6
3 1
4 37
5 49
6 42
7 40
8 15
9 31
10 17
11 1147
12 18
13 30
14 22
15 4
16 25
17 19
18 13
19 27
20 38
21 30

Solution:
Use SPL XLL to enter the formula below:

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

As shown in the picture below:

resutlt table with code entered
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.


This content originally appeared on DEV Community and was authored by Judith-Excel-Sharing


Print Share Comment Cite Upload Translate Updates
APA

Judith-Excel-Sharing | Sciencx (2024-06-19T02:34:58+00:00) In Excel, Find the Maximum Value and the Neighboring N Members Before and After. Retrieved from https://www.scien.cx/2024/06/19/in-excel-find-the-maximum-value-and-the-neighboring-n-members-before-and-after/

MLA
" » In Excel, Find the Maximum Value and the Neighboring N Members Before and After." Judith-Excel-Sharing | Sciencx - Wednesday June 19, 2024, https://www.scien.cx/2024/06/19/in-excel-find-the-maximum-value-and-the-neighboring-n-members-before-and-after/
HARVARD
Judith-Excel-Sharing | Sciencx Wednesday June 19, 2024 » In Excel, Find the Maximum Value and the Neighboring N Members Before and After., viewed ,<https://www.scien.cx/2024/06/19/in-excel-find-the-maximum-value-and-the-neighboring-n-members-before-and-after/>
VANCOUVER
Judith-Excel-Sharing | Sciencx - » In Excel, Find the Maximum Value and the Neighboring N Members Before and After. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/06/19/in-excel-find-the-maximum-value-and-the-neighboring-n-members-before-and-after/
CHICAGO
" » In Excel, Find the Maximum Value and the Neighboring N Members Before and After." Judith-Excel-Sharing | Sciencx - Accessed . https://www.scien.cx/2024/06/19/in-excel-find-the-maximum-value-and-the-neighboring-n-members-before-and-after/
IEEE
" » In Excel, Find the Maximum Value and the Neighboring N Members Before and After." Judith-Excel-Sharing | Sciencx [Online]. Available: https://www.scien.cx/2024/06/19/in-excel-find-the-maximum-value-and-the-neighboring-n-members-before-and-after/. [Accessed: ]
rf:citation
» In Excel, Find the Maximum Value and the Neighboring N Members Before and After | Judith-Excel-Sharing | Sciencx | https://www.scien.cx/2024/06/19/in-excel-find-the-maximum-value-and-the-neighboring-n-members-before-and-after/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.