Logical Operators
Logical operators (and, or, not) enable you to logically combine multiple expressions to evaluate a larger, more complex expression whose output is true
or false
.
(left-hand side) (operator) (right-hand side)
These evaluations result in a Boolean output. The following operators are supported:
Operator Name | Symbol | Example Expression | Output | Notes |
---|---|---|---|---|
and | && | | true | |
| false | |||
or | || | | true | Exclusive or (xor) is not supported. |
| false | |||
not | ! | | false | |
| true |
The above examples apply to integer values only. Below, you can review how the comparison operators apply to different data types.
Usage
Logical operators are used to perform evaluations of expressions covering a variety of data types. Typically, they are applied in evaluations of values or rows.
Example data:
X | Y |
---|---|
true | true |
true | false |
false | true |
false | false |
Transforms:
Transformation Name | |
---|---|
Parameter: Formula type | Single row formula |
Parameter: Formula | (X && Y) |
Parameter: New column name | 'col_and' |
Transformation Name | |
---|---|
Parameter: Formula type | Single row formula |
Parameter: Formula | (X || Y) |
Parameter: New column name | 'col_or' |
Transformation Name | |
---|---|
Parameter: Formula type | Single row formula |
Parameter: Formula | !(or) |
Parameter: New column name | 'col_not_and' |
Transformation Name | |
---|---|
Parameter: Formula type | Single row formula |
Parameter: Formula | !(or) |
Parameter: New column name | 'col_not_or' |
Results:
Your output looks like the following:
X | Y | col_and | col_or | col_not_and | col_not_or |
---|---|---|---|---|---|
true | true | true | true | false | false |
true | false | false | true | true | false |
false | true | false | true | true | false |
false | false | false | false | true | true |
Examples
ヒント
For additional examples, see Common Tasks.
and
Column Type | Example Transform | Output | Notes | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Integer/Decimal |
|
| |||||||||||
Datetime |
| Delete all rows in which the | |||||||||||
String |
| For U.S. State names, the generated column contains
For all other values, the generated value is |
|
or
Column Type | Example Transform | Output | Notes | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Integer/Decimal |
|
| |||||||||||
Datetime |
| Delete all rows in the dataset where the | |||||||||||
String |
|
|
not
Column Type | Example Transform | Output | Notes | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Integer/Decimal |
| Keep all rows for houses that do not meet any of these criteria:
| |||||||||||
Datetime |
| Keep all rows in the dataset where the year of the | |||||||||||
String |
| Delete all rows in which the value of the |