# If...Then...Else Statement

## Recommended Posts

Hi lots,

Is there a functionality of "If...then...else" statements in formulars. Or is there at least a workaround?

##### Share on other sites

Hi AiKju-

There are a couple methods to accomplish this, both of which are summarized in our Knowledge Base.  Take a look at these articles:

1. Using Boolean Signals to Replace IF Statements (

2. Using Conditions and the Splice Function to Replace IF Statements

If there's any additional information you can provide about your Use Case, we may be able to provide some more specific work steps.  Let me know if you have any additional questions.

Lindsey

• 1
##### Share on other sites

Hi Lindsey,

Cn=max[0,Xn - Number + Cn-1]

Dn=min[0,Xn - Number  + Dn-1]

These are rolling sums with kind of a reset button if Cn becomes smaller then 0 it stays 0 and if Dn becomes greater then 0 it stays 0. (You did ask ;-)). By the way the rolling sums should be per value and not per time capsule...

Kai

##### Share on other sites

Hi Aikju-

To calculate the rolling sums, use the .runningSum() function in Formula.  Note that you will be required to provide a condition over which to calculate the rolling sum; this could be calendar days, a production mode condition etc:

Now that you have a signal calculating the rolling sum, a combination of Value Search and the .splice() function in Formula can be used to set the signal equal to 0.  First, lets use Value Search to identify when the running sum is greater than zero:

Before we can use the .splice() function in Formula, we need to create a 0 signal in Formula:

Now, we can use the .splice() function in Formula to splice in the 0 signal whenever the Rolling Sum signal is greater than 0.

Please let me know if this gets you the results that you need or if you have any additional questions.

Lindsey

##### Share on other sites

• 2 weeks later...

Hi Lindsey,

I tried solving this by using the externalCalculation-Function of Seeq. I created a python script and modified the functions initialize and compute as followed:

def initialize(self):
self.sum = 0
pass

def compute(self, key, samples_for_key):
self.sum += samples_for_key
if self.sum < 0:
self.sum = 0
return key, self.sum

The script is called by using externalCalculation('CusumP.py:NUMERIC:M6CBe8UAQoSN',\$d)

However, when I am using this script I get the following error message on execution:

Error getting data: Client data source exception: Error processing external calculation request: Script CusumP.py:NUMERIC:M6CBe8UAQoSN is not respecting the requirement to do only calculations that operate on data at a single key. Script needs to be changed. Exception: java.lang.RuntimeException at 'externalCalculation', line=1, column=1. To retry, use the button to the right.

Why is this behaviour blocked by Seeq?

Thorsten

##### Share on other sites

Thorsten,

It looks as if the second part of your code requires summing values at different keys (timestamps).  At this time Seeq can only pass data for external calculations one key at a time so functions like summing data over time aren't possible because you need more than one key.

I recommend doing the summation in Seeq as Lindsey suggested.

Regards,

Teddy

##### Share on other sites

• 1 year later...

what if you have more than 2 conditions?

For example, you have a valve opening positions of 1 - 5.

And you would need to apply different equation for each opening. How would i set up the Boolean signal for them?

##### Share on other sites

Hi Bella,

you can chain the splice command multiple times: You may also have a look at this post:

Hope this helps.

Regards,

Thorsten