Peak Value of analog input

Hi all,
I need to find the peak value of an analog sensor scaled output.
For eg. Value1 (real) increases from 0.0 to 4.5, and then drops back to 0.0.
in this case i want to save 4.5 in a variable Result1 (real).
Then, Value1 again starts incrementing, this time till 3.9 and drops back to 0.0, i want 3.9 to be saved in Result1.
Next, Value1 again starts incrementing, this time till 4.2 and drops back to 0.0, i want 4.2 to be saved in Result1.
and so on…

How to achieve this? Any ideas, pls share.

peak.PNGOne of the simplest variants.
Best regards.

[https://forum.plcnext-community.net/uploads/KTIWTHE7QFX2/peak-png.png</a></p>One of the simplest variants.</p>Best regards.</p>

Works like a charm
Thank you!