# Help: Average value from signal when a condition is true.

## Recommended Posts

Hello,

Im working on a project that i need to display a signals average when a condition is true.

The signal is:

• WFF FS4H.

The conditions i want to evaluate this signal are the following:

• CRU 4.0 and down
• CRU 4.0-4.5
• CRU 4.5-5.0
• CRU 5.0-5.5
• CRU 5.5 and up

I know how to display the average of the signal for each time one of these conditions become true. But i want to display the cumulative average of the signal for these conditions during per say a 6 month period. Is this possible? For example below: You can see that these conditions are alternating and intermittent.

##### Share on other sites

• Seeq Team

Hello,

yes this is possible and you can do it in different ways:

• You can use the Union Operator to unify all these condition into a single one then calculate the average for each capsule. The Formula tool is useful here and forumula should look like: \$signal.aggregate(average(), \$condition1.union(\$condition2).union(\$condition3).union(\$condition4).union(\$condition5), startKey())
• You can also use formula and the splice operator to achieve similar result: \$signal.aggregate(average(), \$condition1, startKey()).splice(\$signal.aggregate(average(), \$condition2, startKey()), \$condition2).splice(\$signal.aggregate(average(), \$condition3, startKey()), \$condition3)....

With one of the above methods, you will get the average of your signal for each capsule of the conditions 1 to 5.

Finally, as you want to calculate the cumulative average, you can apply the runningsum() formula to the result of the previous step.

Let me know if this is helpful.

• 1
##### Share on other sites

Awesome thank you so much!

##### Share on other sites

• 2 weeks later...
• Seeq Team

Hi Mkuhl70,

Alternatively, you can use the runningAggregate(average()) function in Seeq Formula to calculate the cumulative average of the signal. Kindly refer to the example below.

```\$condition_I_want = \$condition1 or \$condition2

\$sixmonthcondition = periods(6month, 6month)

\$signal.remove(not \$condition_I_want).runningAggregate(average(), \$sixmonthcondition)```

##### Share on other sites

• 4 months later...

Excellent responses to this!  Very helpful.