Operator in Tableau
An operator is referred to as a symbol that often tells the compiler to execute certain mathematical or logical operations. Tableau accepts the same operators which are used by the other spreadsheet program. It has very straightforward operators which are used to create calculated expressions and formulas. For example: +, -, *, / etc.
In general, Tableau supports four types of operators:
- General Operators
- Arithmetic Operators
- Relational Operators
- Logical Operators.
Given-below is a brief explanation of all the above operators:
Tableau General Operators
They are the basic operators which are used in calculations and concatenation of Strings. These operators can act on numeric, character, and date data types.
- Addition or ‘+’
In Tableau the addition operator is used to add two numbers or to concatenate two strings or to add days to dates.
For example: 1.) Adding numbers:
0 1 2 |
7+ 9 = 16 |
2.) Concatenating Two Strings:
0 1 2 |
‘ HELLO’+ ‘WORLD’= ‘HELLOWORLD’ |
3.) Adding Dates:
0 1 2 |
#MAY 22, 2019# + 5 = #MAY 27, 2019# |
- Subtraction or ‘-’
The subtraction operator in the tableau is either used to subtract one number from another or to subtract dates.
For example: 1.) Subtracting numbers:
0 1 2 |
7- 9 = -2 |
2.) Subtracting Dates
0 1 2 |
#MAY 22, 2019# - 5 = #MAY 17, 2019# |
Arithmetic Operators
These operators are used to perform all the mathematical calculations. And these operators act only on numeric data types.
- Multiplication or ‘*’
The multiplication operator is used for numeric multiplication, i.e., to multiply one number from another.
For example:
0 1 2 |
18 * 2= 36 |
- Division or ‘/’
The divide operator is used for numeric division, i.e., to divide one number from another.
For example:
0 1 2 |
18 / 2 = 9 |
- Modulo or ‘%’
The modulo operator is used to find the remainder after dividing the one number from another.
For example:
0 1 2 |
19 % 2= 1 |
- Power or ‘^’
The power operator is used to find the exponent of a value.
For example:
0 1 2 |
2^4 = 16 |
Relational Operators
Relational Operators are also known as comparison operators. It is used to compare one value with another. These operators can act on numeric, character, and date data types. The result is returned in a Boolean value, i.e., either TRUE or FALSE.
- Equals to or ‘==’
The ‘Equals to’ operator compares whether the given two strings, numbers or two dates are equal or not. It returns a Boolean value TRUE if both the fields are identical, else it returns false.
For example:
0 1 2 |
‘Hello’ = ‘Hello’ |
0 1 2 |
5=5 == TRUE |
- Greater than or ‘>’
The ‘Greater than’ operator compares the given two numbers, strings, dates, and checks whether the specified first argument is greater than the second argument. It returns a Boolean value TRUE if it satisfies the above case, else it returns FALSE.
For example:
0 1 2 |
‘Hello’ > ‘Tableau’ |
0 1 2 |
5>7 == FALSE |
- Greater than equal to or ‘> =’
The ‘Greater than equal to’ operator compares the given two numbers, strings or dates, and checks whether the specified first argument is greater or equal to the second argument. It returns a Boolean value TRUE if it satisfies the above case, else it returns FALSE.
For example:
0 1 2 |
‘Hello’ >= ‘Hello’ |
0 1 2 |
5>=5 == TRUE |
- Smaller than or ‘<’
The ‘Smaller than’ operator compares the given two numbers, strings or dates, and checks whether the specified first argument is smaller than the second argument. It returns a Boolean value TRUE if it satisfies the above case, else it returns FALSE.
For example:
0 1 2 |
‘Hello’ < ‘Tableau’ |
0 1 2 |
5< 7 == TRUE |
- Smaller than equal to or ‘< =’
The ‘Smaller than equal to’ operator compares the given two numbers, strings or dates, and checks whether the specified first argument is smaller or equal to the second argument. It returns a Boolean value TRUE if it satisfies the above case, else it returns FALSE.
For example:
0 1 2 |
'Hello’ <= ‘Hello’ |
0 1 2 |
5<=5 == TRUE |
- Not equals to or ‘!=’ or ‘<>’
The ‘Not equals to’ operator compares whether the given two strings, numbers or two dates are equal or not. It returns a Boolean value TRUE if both the fields are unequal, else it returns false.
For example:
0 1 2 |
‘Hello’ <> ‘Tableau’ |
0 1 2 |
5<>7 == TRUE |
Logical Operators
Logical Operators returns Boolean values giving the result as TRUE or FALSE.
- AND
The ‘AND’ operator returns a Boolean value TRUE if either the expressions or the Boolean values present on the sides of AND operator is estimated to be TRUE. Else it returns FALSE.
For example:
0 1 2 |
[Ship Date] > #March 23, 2019# AND [Loss] > 89000 |
- OR
The ‘OR’ operator returns a Boolean value TRUE if any of the given expression and Boolean or both the expressions and the Boolean values present on the sides of OR operator is estimated to be TRUE. Else it returns FALSE.
For example:
0 1 2 |
[Ship Date] > #March 23, 2019# OR [Loss] > 89000 |
- NOT
The ‘NOT’ operator negates the Boolean value of the expression that is present after it.
For example:
0 1 2 |
[Ship Date] > #March 23, 2019# NOT [Loss] > 89000 |
OPERATOR PRECEDENCE
Tableau also follows the operator precedence order for evaluating its calculations. Operators which are present on the same row also have the same precedence. And if two operators have the same priority, they are weighed from left to right in the formula for the calculations. The parentheses can also be used, but the inner brackets are valued before the outer parentheses. The following table describes the priority in which operators precedence are decided:
OPERATORS |
PRECEDENCE |
postfix increment and decrement | ++, — |
Negate prefix increment and decrement, and unary | ++, –, -(negate), ~ ! |
Power | ^ |
Multiplicative/divide/ Modulo | * / % |
Additive/ subtractive | + – |
Shift | <<>>>>> |
Relational | <><= >= instanceof |
Equality | == != |
logical AND | && |
logical OR | || |
Assignment | = += -= *= /= %= &= ^= |= <<= >>=>>>= |
by