Skip to content
Advertisement

Find minimum and show the area/values around it

I would like to find a minimum in a very long time series, but instead of show the whole series with 2000 points, or only 1 line, I want to show the 20 rows with the profit value before and after the minimum,

result example :

So, per company, find the minimum, then print the “area” around the minimum, say 10 results before and after.

Goal is to print the area of the minimum with a line that show minimum.

This gives me a single line result:

EDIT:

To clarify, thanks to the comments here, if minimum 2 was on August 15, i want to show all results between 10-20th August. date_time is a number date which show the date in days as int number in seconds. (epoch)

Advertisement

Answer

You need two steps:

  • find the minimum rows
  • find their surrounding rows

For this, determine the minimum profit with MIN OVER and also number the rows with ROW_NUMBER. Thus you can then select all rows the row number of which is not farther away than 10 from the minimum rows’ row number.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement