# End Value of a Signal on the Previous Capsule of a Condition

## Recommended Posts

Hello,

I have a signal which I integrate over a condition. Of course, it starts from zero for each capsule of the condition and integrates.

I need to create a signal with two terms being added:
Signal=(Integral Signal)+(End Value of the Integral Signal at the Previous Capsule)

The signal can reset to zero at the start of each month.

i.e. Pin 3 at the screenshot below is placed at the end of the first capsule of the May (it seems like the first capsule extends back to the previous month but it is actually split at the end/start of month), the value is 10.787 h. I want the next integration through the next capsule to shift up in the y-axis by 10.787 h. And the 3rd capsule to shift up by whatever the result of 2nd capsule would be and so on until the end of the month, resetting to zero only at the start of each month.

Would you recommend a way to achieve this?

##### Share on other sites

Hi Emre,

you could try to sum up the running deltas for each months:

`\$signal.setMaxInterpolation(20d).runningdelta().runningSum(months('CET'))`

Regards,

Thorsten

• 1
##### Share on other sites

Hi Thorsten,

This worked perfectly well. Thank you very much!

Regards,

Emre

##### Share on other sites

• 2 weeks later...

Hello again,

In the same case, there is a condition (say condition A) that lights up sometimes, creating capsules in between purple capsules in Thorsten's example. I want to add a constant value (say +3) to the running sum of the running delta If A lights up in between the purple condition's capsules. Would you recommend a solution for this?

Best Regards,

Emre

##### Share on other sites

Hi Emre,

one way to achieve this would be counting the conditions and multiply them with you constant. This signal is then added to the other signal:

```\$signal.setMaxInterpolation(20d).runningdelta().runningSum(months('CET')) +
\$conditionA.aggregate(count(), \$conditionA, startKey(), 0s).runningCount(months('CET')).toStep(30d) * 3```

The second term of the formula will calculate the number of capsules during each capsule (which is 1) and put that as a discrete value to the start of the capsule. This value will be summed up during the month, transformed to a step signal and multiplied with the constant.
The screenshot shows the previous calculation (red) together with the new calculation (blue). Condition A is represented by the green capsules.

Regards,

Thorsten