📜  Tableau-运算符

📅  最后修改于: 2020-11-29 08:33:22             🧑  作者: Mango


运算符是一个符号,告诉编译器执行特定的数学或逻辑操作。 Tableau具有许多用于创建计算字段和公式的运算符。

以下是可用的运算符的详细信息以及操作的顺序(优先级)。

运营商类型

  • 一般操作员
  • 算术运算符
  • 关系运算符
  • 逻辑运算符

一般操作员

下表显示了Tableau支持的常规运算符。这些运算符作用于数字,字符和日期数据类型。

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#

算术运算符

下表显示了Tableau支持的算术运算运算符。这些运算符仅对数字数据类型起作用。

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

比较运算符

下表列出的Tableau支持的比较运算符。这些运算符用于表达式中。每个运算符比较两个数字,日期或字符串,并返回一个布尔值(TRUE或FALSE)。但是,布尔值本身无法使用这些运算符进行比较。

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#

逻辑运算符

下表显示了Tableau支持的逻辑运算符。这些运算符用于结果为布尔值的表达式中,输出为TRUE或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#

运算符优先级

下表描述了评估运算符的顺序。第一排具有最高优先级。同一行上的运算符具有相同的优先级。如果两个运算符的优先级相同,则会在公式中从左到右对其求值。也可以使用括号。在内括号之前先评估内括号。

Precedence Operator
1 –(negate)
2 ^(power)
3 *, /, %
4 +, –
5 ==, >, <, >=, <=, !=
6 NOT
7 AND
8 OR