Skip to main content

IF

Updated over a month ago

An IF statement is split into two separate areas and all parameters of the 'If statement' are separated with commas

  1. The Test.

  2. The Result.

The TEST

The first section of an 'if statement' can be referred to as the 'Test' it has to compare two numerical values. If the field that is being tested is a character value then that field has to be converted into a numerical value to do the 'Test'. (see calculations on character values)

The RESULT

The result will either be a true or false answer. Without the specification of any true and false results an if statement will automatically return a 1 if true and a 0 if false. Therefore it may be a simple test between two numbers and can be defined as follows:

Simple examples of an 'IF statement'.

IF(a,EQ,b); returns 1 if true / 0 if false
IF(a,EQ,b,truevalue,falsevalue); returns truevalue if true /falsevalue

if false.
​

The operands available for use within the IF function are :

EQ

Equal To

NE

Not Equal To

LT

Less Than

GT

Greater Than

LE

Less Than or Equal To

GE

Greater Than or Equal To

If the'Result' of an IF statement needs to be a character value then the IF statement must be encapsulated within $ signs.

$IF$(a,eq,b,"Yes","No")

If a variable is to be assigned then the variable will be situated between the first $ sign and the IF statement.

$var=IF$(a,eq,b,"Yes","No")

NB : Using an IF statement to create a simple Flag, in the example below the calculation is setting a variable, dFlag, to either 1 or 0 depending on the comparison of the Valuation Due Date against the Report Selection Date passed through to the report - this flag can be used to multiply values in other fields.

dFlag = IF(datestring(cs_valcert.cvc_duedate),LT,datestring('{RS_date__2}'),1,0);

Note : Date format fields require special consideration – please see below.


Example of above:

Field1={RO_ContractCosts^TD} * dFlag

Field2={RO_ContractRevenue^TD} * dFlag

Field3=({RO_ContractRevenue^TD} - {RO_ContractCosts^TD}) * dFlag

This means that only when the dFlag is true will these figures for Field1,Field2 & Field 3 will appear as a multiplication by Zero will return value of Zero.

Did this answer your question?