📜  Tableau-函数

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


任何数据分析都涉及大量计算。在Tableau中,计算编辑器用于将计算应用于要分析的字段。 Tableau具有许多内置函数,可帮助创建用于复杂计算的表达式。

以下是对不同功能类别的描述。

  • 数字功能
  • 字符串函数
  • 日期功能
  • 逻辑功能
  • 汇总功能

数字功能

这些是用于数值计算的函数。他们仅将数字作为输入。以下是一些重要数字函数的示例。

Function Description Example
CEILING (number) Rounds a number to the nearest integer of equal or greater value. CEILING(2.145) = 3
POWER (number, power) Raises the number to the specified power. POWER(5,3) = 125
ROUND (number, [decimals]) Rounds the numbers to a specified number of digits. ROUND(3.14152,2) = 3.14

字符串函数

字符串函数用于字符串操作。以下是一些重要的字符串函数和示例

Function Description Example
LEN (string) Returns the length of the string. LEN(“Tableau”) = 7
LTRIM (string) Returns the string with any leading spaces removed. LTRIM(” Tableau “) = “Tableau”
REPLACE (string, substring, replacement) Searches the string for substring and replaces it with a replacement. If the substring is not found, the string is not changed. REPLACE(“GreenBlueGreen”, “Blue”, “Red”) = “GreenRedGreen”
UPPER (string) Returns string, with all characters uppercase. UPPER(“Tableau”) = “TABLEAU”

日期功能

Tableau具有各种日期功能,可以执行涉及日期的计算。所有日期函数都使用date_part ,这是一个字符串,指示日期的一部分,例如-月,日或年。下表列出了一些重要的日期函数示例。

Function Description Example
DATEADD (date_part, increment, date) Returns an increment added to the date. The type of increment is specified in date_part. DATEADD (‘month’, 3, #2004-04-15#) = 2004-0715 12:00:00 AM
DATENAME (date_part, date, [start_of_week]) Returns date_part of date as a string. The start_of_week parameter is optional. DATENAME(‘month’, #200404-15#) = “April”
DAY (date) Returns the day of the given date as an integer. DAY(#2004-04-12#) = 12
NOW( ) Returns the current date and time. NOW( ) = 2004-04-15 1:08:21 PM

逻辑功能

这些函数对某个单个值或表达式的结果求值,并产生布尔输出。

Function Description Example
IFNULL (expression1, expression2) The IFNULL function returns the first expression if the result is not null, and returns the second expression if it is null. IFNULL([Sales], 0) = [Sales]
ISDATE (string) The ISDATE function returns TRUE if the string argument can be converted to a date, and FALSE if it cannot.

ISDATE(“11/05/98”) = TRUE

ISDATE(“14/05/98”) = FALSE

MIN(expression) The MIN function returns the minimum of an expression across all records or the minimum of two expressions for each record.

汇总功能

Function Description Example
AVG(expression) Returns the average of all the values in the expression. AVG can be used with numeric fields only. Null values are ignored.
COUNT (expression) Returns the number of items in a group. Null values are not counted.
MEDIAN (expression) Returns the median of an expression across all records. Median can only be used with numeric fields. Null values are ignored.
STDEV (expression) Returns the statistical standard deviation of all values in the given expression based on a sample of the population.