Boolean and conditional logic functions
Boolean and conditional logic functions compare values and return results based on conditions. Use them to filter data, such as orders from one region, or to label rows with different values. Before you start, review the NetScript language reference for formula syntax.
if..then..else
Use the if expression to return different results based on conditions, such as labeling orders as large or small. Analytics checks each condition in order and returns the result of the first true condition. The else branch is optional. Without it, the result is null when no condition is true.
Function
if CONDITION_1 then RESULT_1 end
if CONDITION_1 then RESULT_1 else RESULT_2 end
if CONDITION_1 then RESULT_1 else if CONDITION_2 then RESULT_2 else RESULT_3 endData type – input type
Example
if 'test' == 'test' then true else if 'test2' == 'test2' then true else false end
if 'test' == 'test1' then 'test1 success' else if 'test2' == 'test2' then 'test 2 success' endResult
true
test 2 successnot (BOOL)
Use the not operator to reverse a boolean value, such as to exclude orders that match a condition. The result is true when the input is false, and false when the input is true.
Function
not (BOOL)Data type – boolean
Example
not ('a' == 'b')
not ('a' != 'b')Result
true
falseBOOL_1 or BOOL_2
Use the or operator to check whether at least one of two conditions is true. For example, find orders shipped by air or by rail.
Function
BOOL_1 or BOOL_2Data type – boolean
Example
'a' != 'b' or 'a' == 'b'
'a' == 'b' or 'a' == 'b'Result
true
falseBOOL_1 and BOOL_2
Use the and operator to check whether both conditions are true. For example, find priority orders shipped by air.
Function
BOOL_1 and BOOL_2Data type – boolean
Example
'a' == 'a' and 'b' == 'b'
'a' != 'b' and 'a' == 'b'Result
true
falseINPUT_1 == INPUT_2
Use the == operator to check whether two values are equal, such as orders with a specific status.
Function
INPUT_1 == INPUT_2Data type – boolean
Example
'snow' == 'snow'
'snow' == 'food'Result
true
falseINPUT_1 != INPUT_2
Use the != operator to check whether two values are different, such as orders that are not canceled. When one side is a fixed value, such as 'snow', and the other side is null, the result is true.
Function
INPUT_1 != INPUT_2Data type – boolean
Example
'snow' != 'food'
'snow' != 'snow'Result
true
falseINPUT_1 < INPUT_2
Use the < operator to check whether the first value is less than the second value. For example, find orders below a price threshold.
Function
INPUT_1 < INPUT_2Data type – boolean
Example
57 < 65
65 < 57Result
true
falseINPUT_1 > INPUT_2
Use the > operator to check whether the first value is greater than the second value. For example, find orders above a price threshold.
Function
INPUT_1 > INPUT_2Data type – boolean
Example
52 > 43
43 > 52Result
true
falseINPUT_1 <= INPUT_2
Use the <= operator to check whether the first value is less than or equal to the second value. For example, find orders with a quantity of 10 or fewer.
Function
INPUT_1 <= INPUT_2Data type – boolean
Example
18 <= 19
19 <= 18Result
true
falseINPUT_1 >= INPUT_2
Use the >= operator to check whether the first value is greater than or equal to the second value. For example, find orders with a quantity of 10 or more.
Function
INPUT_1 >= INPUT_2Data type – boolean
Example
74 >= 23
23 >= 74Result
true
falseis_null(INPUT)
Use the is_null function to check whether a value is null, such as orders with no discount. The input accepts any data type. To check for a value that is not null, use not (is_null(INPUT)).
Function
is_null(INPUT)Data type – boolean
Example
is_null(Orders.Discount)Result
true for orders with no discountINPUT in [VALUE_1, VALUE_2]
Use the in operator with a list to check whether a value matches any value in the list. For example, find orders that use one of several ship modes. Every value in the list must have the same data type as the input. The equivalent function form is in_list(INPUT, VALUE_1, VALUE_2), with each value as a separate argument. To check a range of numbers, use [START..END], such as Orders.Priority in [1..5]. The range includes both ends.
Function
INPUT in [VALUE_1, VALUE_2]Data type – boolean
Example
Orders.ShipMode in ['air', 'rail']
Orders.Priority in [0, 1, 2]Result
true for orders shipped by air or rail
true for orders with priority 0, 1, or 2INPUT in all_values
Use the all_values keyword with in to match every value, such as the default of a filter parameter. The expression returns true for every value.
Function
INPUT in all_valuesData type – boolean
Example
Orders.ShipMode in all_valuesResult
trueINPUT == all_values
Use the all_values keyword with == to match every value, such as the default of a filter parameter. The expression returns true for every value.
Function
INPUT == all_valuesData type – boolean
Example
Orders.ShipMode == all_valuesResult
true