Retrieve the rows before and after max value in a column

Hi everyone,

Let’s say, I have a shop and I want to make some stats on the sales to check when are the best and worst sales. This part is quite simple, I found a topic on this already here (How to find Min / Max in a column - #4).

But now let’s add some spice, the financial benefits of the shop are processed by 1-day periods except when it is a weekend or a holiday. The processed data look like this :

Date Financial Benefits
2022-04-01 4 608 ₽
2022-04-02 3 979 ₽
2022-04-03 15 215 ₽
2022-04-05 24 711 ₽
2022-04-06 4 172 ₽
2022-04-07 6 058 ₽
2022-04-08 5 775 ₽
2022-04-09 2 254 ₽
2022-04-10 25 789 ₽
2022-04-12 42 489 ₽
2022-04-13 6 672 ₽

As explained above, I am able to find the maximum/minimum values and the associated date with the following modules :
image

For statistic issues I also need for both dates (max/min benefits) to get the date for both the previous and the following report to check the date difference.
For exemple, for the maximum value (42 489 ₽), the previous report was on 2022-04-10 (2 days before) and the following was on 2022-04-13 (1 day after).

The processed data are already sorted by date (with no blank lines) so I would need the previous and the following line. Do you have any idea on how I can retrieve them ?

Thank you and have a nice weekend.

Hello my friend,

I hope Lag Column node helps you.

2 Likes

I used the “Lag Column node” to retrieve the previous date and in parallel I sorted my values in the descending order to do the same operation and retrieve the following date. It works well, thanks.

1 Like

I am fairly sure that you could extract the row of the max value using column expressions node as well, but never tried it.
rowID(colMAX(“yourcolumn name”))

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.