# EXCEL IF(x,y1,y2)

## Recommended Posts

What is the best way to create a formula that will give me the equivalent of the Excel if function.  The specific example I have is if a control valve is closed (.OP <= 0) then I want the formula to give me zero flow, other wise I want it to just give me the flow reading.  So something like this in Excel

IF(OP<=0,0,FLOW)

##### Share on other sites

• Seeq Team

Hi Tommy,

The easiest way to do this in Seeq is to use a condition to define the if condition, and then splice in a new signal when your condition is true. Follow the steps below to achieve this.

1) Use the Value Search tool to find when your signal .OP <= 0

2) In Formula, enter the following:

`\$flowsignal.splice(0.toSignal(), \$conditionclosed)`

where \$flowsignal is your Flow Rate signal, and \$conditionclosed is the condition we created in Step 1. What we are doing here is splicing in a new signal we create ( 0.toSignal() ) which will equal 0 when the .OP <= condition is true.

You could also write all of this into 1 Formula (combining steps 1 & 2 together) by writing the following:

```\$conditionclosed = \$OP.validValues().valueSearch(isLessThanOrEqualTo(0))
\$flowsignal.splice(0.toSignal(),\$conditionclosed)```

-Kjell

Edited by Kjell Raemdonck
added option to write all into 1 formula
• 2
• 1
##### Share on other sites

• 2 weeks later...

What benefit does .valueSearch()   provide?

I've typically written it this way and see no difference of outcome

```\$conditionclosed = \$OP.validValues().isLessThanOrEqualTo(0)
\$flowsignal.splice(0.toSignal(),\$conditionclosed)```
• 1
##### Share on other sites

• Seeq Team

When generating a simple value search, using operators like .isLessThan() or using the mathematical operators in formula like <,>  would generally be more efficient than specifying a Value Search.

The .valueSearch() operator provides aditional benefit over other operators when some condition filtering is also required as we can also specify an entry/exit grace period, and max duration, among other possible operators that can be supplied directly into the valueSearch() operator without having to use other fucntions to accomplish condition filtering.

An example where .ValueSearch() would be much simpler than using .isbetween() and other condition filtering operators would be:

Create capsules where `\$signal` becomes greater than 5 kW for at least 4 seconds and ending when \$signal becomes greater than 15.0 kW for at least 3 seconds. Capsules longer than 1 day are discarded.

`\$signal.valueSearch(1d, isGreaterThan(5.0 kW), 4s, true,`
`    isGreaterThan(15.0 kW), 3s, true)`
• 2
##### Share on other sites

Makes sense, thanks!