I have two columns of calculated values, x and y, 5000 rows. If you graph it, it looks like a three-humped camel–i.e. it has three local peaks in the y values.

As I change various inputs to the calculation, the locations of the peaks changes (i.e. a peak in the y value will appear at a different x, a different row).

I can identify the peaks with a formula like this:

=AND(OFFSET(W6, -1, 0)<W6, W6>OFFSET(W6, 1, 0))

This looks for values of y which are greater than the one before and the one after.

What I want is to produce a 2x3 array of the three x,y pairs where the above expression is true. This can’t just be a copy&paste since the rows at which these peaks occur changes. In fact, it can’t be a manual process at all, since there are further formulas which work on this 2x3 array, so I need those to recalc when the peaks change, no human involved.

I did this in Google Sheets with a named function:

```
name: FIND_PEAKS
parameters: x, y
Definition:
=REDUCE({0,0}, y, LAMBDA(accum, curr,
IF(AND(offset(curr, -1, 0)<curr, curr>offset(curr, 1, 0)),
VSTACK(accum, {INDEX(x, ROW(curr)-ROW(x)+1, 1),curr})
,
accum
)
))
```

Unfortunately, REDUCE and LAMBDA are not supported in LO Calc.

Is there another way?

I’ve attached the spreadsheet.

Medium SS.ods (66.1 KB)

Look at cell model!B65 to see what the desired result should look like. The x,y pairs are in sheet “freq_db”, and are labeled “f” and “db”.

Thanks for any help you can offer.

Greg