Skip to content

Logical functions

Logical functions in FastStats allow conditional operation.

They can also be used to set a value according to the result. The value returned is 0.0 if the expression evaluates to false, 1.0 if the expression evaluates to true, or missing value if the answer is undefined due to missing values.

If

  • If (A,B,C) - if condition A then use value B else use value C.
  • If (A,B) - if condition A then use value B else use missing value.

Examples:

Expression
If( [Cost] < 1000 , 1, 0)
Expression
If( AgeWeeks([Booking Date]) <= 52, 0, 69)

Case

Case(A,a,B,b,C,c ...) – if condition A then use value a, condition B then use value b, etc..

Examples:

Expression
Case( [Cost] = 100, 1,
      [Cost] = 200, 2,
      [Cost] = 300, 3)
Expression
Case( [Cost] < 500, 1,)

Or

Or(A,B,C...) - evaluates to true if condition A is true OR condition B is true etc., otherwise evaluates to false.

Expression
If( Or ([Cost]<1000,[Cost]=1000),1,0)

And

And(A,B,C...) - evaluates to true if condition A is true AND condition B is true etc., otherwise evaluates to false.

Expression
If( And([Cost]>500,[Cost]<1000),1,0)

InList

InList(X,A,B,C ...) - greater than 1 if expression X takes value of expression A or B or C ...

Example:

Expression
If( InList(790.00, [Cost],[Cost]+10,[Cost]-10),1,0)

This will return 1 if [Cost] is 790, 2 if ([Cost]+10) is 790, etc.

InListAllMatches

Calculates the value of the “Expression” defined in the first parameter.

Expression
InListAllMatches(Expression, Value 1, Value 2, )

The result of this expression can be a numeric, string or date type. The “Values” are then checked against the result.

Returns a numeric list containing the index of all the value parameters which match the expression result. If there is no match then empty list is returned. You can also set the match parameters from a list.

For example, InListAllMatches(Product Code, "ABC", "DEF", "GHI") returns a numeric list with 1 in it if the Product Code is ABC, 2 in it if it is DEF, 3 in it if it is GHI, and an empty list if none of them match.

Index

Index(X,A,B,C ...) selects Xth item (1-based) from the list (A,B,C ...).

For example:

Expression
Index(2,1,2,3)
The above expression returns 2.

The match parameters can also be set from a list.

IndexFromList

Calculates the values of the “NumericList Expression” defined in the first parameter.

Expression
IndexFromList(NumericList Expression, Value 1, Value 2, )

Returns a list of the values represented by the corresponding positions in the list of "Values". You can also set the match parameters from a list.

For example, IndexFromList(CreateList(2, 3), "a", "b", "c") returns a list with "b" and "c" in it.

MaxIndex

Returns the index of the maximum value in a list of values

For example:

Expression
MaxIndex(4,9,2,4,5)

The above expression returns 2.

The second number is the highest in this list.

MinIndex

Returns the index of the minimum value in a list of values.

For example:

Expression
MinIndex(4,9,2,4,5)

The above expression returns 3.

The third number is the lowest in this list.

Not

Returns the logical opposite of the input logical expression.

Examples:

Expression
10 > 5 returns 1 (true)
Expression
Not(10 > 5) returns 0 (false)

ValidEmail

Determines whether an email address is in a valid format.

Expression
ValidEmail([Email Address])

Returns 1 if true and 0 if false.