Tableau 简明教程
Tableau - Operators
运算符是一个符号,它告诉编译器执行特定的数学或逻辑操作。Tableau 具有许多运算符,用于创建计算字段和公式。
An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations. Tableau has a number of operators used to create calculated fields and formulas.
以下是可用运算符的详细信息以及运算的顺序(优先级)。
Following are the details of the operators that are available and the order (precedence) of operations.
Types of Operator
-
General Operators
-
Arithmetic Operators
-
Relational Operators
-
Logical Operators
General Operators
下表显示了 Tableau 支持的通用运算符。这些运算符作用于数字、字符和日期数据类型。
Following table shows the general operators supported by Tableau. These operators act on numeric, character, and date data types.
Operator |
Description |
Example |
+(addition) |
Adds two numbers. Concatenates two strings. Adds days to dates. |
7 + 3 Profit + Sales 'abc' + 'def' = 'abcdef' April 15, 2004 + 15 = April 30, 2004 |
–(subtraction) |
Subtracts two numbers. Subtracts days from dates. |
-(7+3) = -10 April 16, 2004 - 15 = April 1, 2004 |
Arithmetic Operators
下表显示了 Tableau 支持的算术运算符。这些运算符仅对数字数据类型起作用。
Following table shows the arithmetic operators supported by Tableau. These operators act only on numeric data types.
Operator |
Description |
Example |
*(Multiplication) |
Numeric multiplication |
23*2 = 46 |
/(Division) |
Numeric division |
45/2 = 22.5 |
%(modulo) |
Reminder of numeric division |
13 % 2 = 1 |
^(power) |
Raised to the power |
2^3 = 8 |
Comparison Operators
下表列出了 Tableau 支持的比较运算符。这些运算符用于表达式中。每个运算符将比较两个数字、日期或字符串,并返回布尔值(真或假)。然而,布尔值本身无法使用这些运算符比较。
Following table lists the comparison operators supported by Tableau. These operators are used in expressions. Each operator compares two numbers, dates, or strings and returns a Boolean (TRUE or FALSE). Booleans themselves, however, cannot be compared using these operators.
Operator |
Description |
Example |
= = or = (Equal to) |
Compares two numbers or two strings or two dates to be equal. Returns the Boolean value TRUE if they are, else returns false. |
‘Hello’ = ‘Hello’ 5 = 15/ 3 |
!= or <> (Not equal to) |
Compares two numbers or two strings or two dates to be unequal. Returns the Boolean value TRUE if they are, else returns false. |
‘Good’ <> ‘Bad’ 18 != 37 / 2 |
> (Greater than) |
Compares two numbers or two strings or two dates where the first argument is greater than second. Returns the boolean value TRUE if it is the case, else returns false. |
[Profit] > 20000 [Category] > ‘Q’ [Ship date] > April 1, 2004 |
< (Less than) |
Compares two numbers or two strings or two dates where the first argument is smaller than second. Returns the boolean value TRUE if it is the case, else returns false. |
[Profit] < 20000 [Category] < ‘Q’ [Ship date] < April 1, 2004 |
Logical Operators
下表显示了 Tableau 支持的逻辑运算符。这些运算符用于表达式中,该表达式的结果为布尔值,输出为真或假。
Following table shows the logical operators supported by Tableau. These operators are used in expressions whose result is a Boolean giving the output as TRUE or FALSE.
Operator |
Description |
Example |
AND |
If the expressions or Boolean values present on both sides of AND operator is evaluated to be TRUE, then the result is TRUE. Else the result is FALSE. |
[Ship Date] > April 1, 2012 AND [Profit] > 10000 |
OR |
If any one or both of the expressions or Boolean values present on both sides of AND operator is evaluated to be TRUE, then the result is TRUE. Else the result is FALSE. |
[Ship Date] > April 1, 2012 OR [Profit] > 10000 |
NOT |
This operator negates the Boolean value of the expression present after it. |
NOT [Ship Date] > April 1, 2012 |
Operator Precedence
下表描述了运算符的评估顺序。最上面一行优先级最高。处于同一行的运算符具有相同的优先级。如果两个运算符具有相同的优先级,则从左到右在公式中对其进行评估。还可以使用括号。圆括号内侧内容在圆括号外侧内容前评估。
The following table describes the order in which operators are evaluated. The top row has the highest precedence. Operators on the same row have the same precedence. If two operators have the same precedence, they are evaluated from left to right in the formula. Also parentheses can be used. The inner parentheses are evaluated before the outer parentheses.
Precedence |
Operator |
1 |
–(negate) |
2 |
^(power) |
3 |
*, /, % |
4 |
+, – |
5 |
==, >, <, >=, ⇐, != |
6 |
NOT |
7 |
AND |
8 |
OR |