Hello Sregej .. Thanks for posting on PI Square .. our community !
The difficult part about your request is how to detect the peak. I am not sure how your data set looks like, but according to the example, the criteria of determining a peak of 'y' is the following :
1- y is greater than 0 or any reasonable value.
2- y stabilizes for certain time 'x'.
So what you can do is to implement PI Asset Analytics to store 'y-value' when it did not change for a specified time interval 'x minutes'. Please refer to Expression functions reference to see the available expression functions and their syntax.
For instance, in your case:
1- You can check if the value is changed or no using 'haschanged' function and specify the 'x minutes' to consider a peak situation. If the answer is false, then this is a peak.
2- You can use an if statement to check if the value is greater than 0 and the peak flag is false. If the condition is valid it stores the 'y_Value"
3- You can use the 'TagTot' function to sum all the stored "Y_values" when the peak condition is valid.
The same idea can be achieved by using performance equations. But Asset Analytics will not consume a PI Tag if you are not historizing the results and you can back-fill it to cover any time interval in the past (Which answers your second question).
Please let me know if you have further questions regarding this !