0% found this document useful (0 votes)
123 views

Tableau Calculation

Uploaded by

dipti dongarde
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
123 views

Tableau Calculation

Uploaded by

dipti dongarde
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 33

Number functions

ABS
Syntax ABS(number)
Output Number (positive)
Definition Returns the absolute value of the given <number>.
Example ABS(-7) = 7
ABS([Budget Variance])

The second example returns the absolute value for all the numbers contained in the
Budget Variance field.
Notes See also SIGN.
ACOS
Syntax ACOS(number)
Output Number (angle in radians)
Definition Returns the arccosine (angle) of the given <number>.
Example ACOS(-1) = 3.14159265358979
Notes The inverse function, COS, takes the angle in radians as the argument and returns the
cosine.
ASIN
Syntax ASIN(number)
Output Number (angle in radians)
Definition Returns the arcsine (angle) of a given <number>.
Example ASIN(1) = 1.5707963267949
Notes The inverse function, SIN, takes the angle in radians as the argument and returns the
sine.
ATAN
Syntax ATAN(number)
Output Number (angle in radians)
Definition Returns the arctangent (angle) of a given <number>.
Example ATAN(180) = 1.5652408283942
Notes The inverse function, TAN, takes the angle in radians as the argument and returns the
tangent.

See also ATAN2 and COT.


ATAN2
Syntax ATAN2(y number, x number)
Output Number (angle in radians)
Definition Returns the arctangent (angle) between two numbers (x and y). The result is in
radians.
Example ATAN2(2, 1) = 1.10714871779409
Notes See also ATAN, TAN, and COT.
CEILING
Syntax CEILING(number)
Output Integer
Definition Rounds a <number> to the nearest integer of equal or greater value.
Example CEILING(2.1) = 3
Notes See also FLOOR and ROUND.
Database CEILING is available through the following connectors: Microsoft Excel, Text File,
limitations Statistical File, Published Data Source, Amazon EMR Hadoop Hive, Amazon
Redshift, Cloudera Hadoop, DataStax Enterprise, Google Analytics, Google
BigQuery, Hortonworks Hadoop Hive, MapR Hadoop Hive, Microsoft SQL Server,
Salesforce, Spark SQL.

DIV
Syntax DIV(integer1, integer2)
Output Integer
Definitio Returns the integer part of a division operation, in which <integer1> is divided by <integer2>.
n
Example DIV(11,2) = 5

EXP
Syntax EXP(number)
Output Number
Definition Returns e raised to the power of the given <number>.
Example EXP(2) = 7.389
EXP(-[Growth Rate]*[Time])
Notes See also LN.
FLOOR
Syntax FLOOR(number)
Output Integer
Definition Rounds a number to the nearest <number> of equal or lesser value.
Example FLOOR(7.9) = 7
Notes See also CEILING and ROUND.
Database FLOOR is available through the following connectors: Microsoft Excel, Text File, Statistical
limitations File, Published Data Source, Amazon EMR Hadoop Hive, Cloudera Hadoop, DataStax
Enterprise, Google Analytics, Google BigQuery, Hortonworks Hadoop Hive, MapR Hadoop
Hive, Microsoft SQL Server, Salesforce, Spark SQL.
HEXBINX
Syntax HEXBINX(number, number)
Output Number
Definitio Maps an x, y coordinate to the x-coordinate of the nearest hexagonal bin. The bins have side
n length 1, so the inputs may need to be scaled appropriately.
Example HEXBINX([Longitude]*2.5, [Latitude]*2.5)
Notes HEXBINX and HEXBINY are binning and plotting functions for hexagonal bins. Hexagonal bins
are an efficient and elegant option for visualizing data in an x/y plane such as a map. Because
the bins are hexagonal, each bin closely approximates a circle and minimizes variation in the
distance from the data point to the center of the bin. This makes the clustering both more
accurate and informative.
HEXBINY
Syntax HEXBINY(number, number)
Output Number
Definitio Maps an x, y coordinate to the y-coordinate of the nearest hexagonal bin. The bins have side
n length 1, so the inputs may need to be scaled appropriately.
Example HEXBINY([Longitude]*2.5, [Latitude]*2.5)
Notes See also HEXBINX.
LN
Syntax LN(number)
Output Number

The output is Null if the argument is less than or equal to zero.


Definition Returns the natural logarithm of a <number>.
Example LN(50) = 3.912023005
Notes See also EXP and LOG.
LOG
Syntax LOG(number, [base])

If the optional base argument isn't present, base 10 is used.


Output Number
Definition Returns the logarithm of a number for the given base.
Example LOG(16,4) = 2
Notes See also POWER LN.
MAX
Syntax MAX(expression) or MAX(expr1, expr2)
Output Same data type as the argument, or NULL if any part of the argument is null.
Definitio Returns the maximum of the two arguments, which must be of the same data type.
n
MAX can also be applied to a single field as an aggregation.
Example MAX(4,7) = 7
MAX(#3/25/1986#, #2/20/2021#) = #2/20/2021#
MAX([Name]) = "Zander"
Notes For strings
MAX is usually the value that comes last in alphabetical order.

For database data sources, the MAX string value is highest in the sort sequence defined by the
database for that column.

For dates

For dates, the MAX is the most recent date. If MAX is an aggregation, the result will not have a
date hierarchy. If MAX is a comparison, the result will retain the date hierarchy.

As an aggregation

MAX(expression) is an aggregate function and returns a single aggregated result. This displays
as AGG(expression) in the viz.

As a comparison

MAX(expr1, expr2) compares the two values and returns a row-level value.

See also MIN.


MIN
Syntax MIN(expression) or MIN(expr1, expr2)
Output Same data type as the argument, or NULL if any part of the argument is null.
Definitio Returns the minimum of the two arguments, which must be of the same data type.
n
MIN can also be applied to a single field as an aggregation.
Example MIN(4,7) = 4
MIN(#3/25/1986#, #2/20/2021#) = #3/25/1986#
MIN([Name]) = "Abebi"
Notes For strings

MIN is usually the value that comes first in alphabetical order.

For database data sources, the MIN string value is lowest in the sort sequence defined by the
database for that column.

For dates

For dates, the MIN is the earliest date. If MIN is an aggregation, the result will not have a date
hierarchy. If MIN is a comparison, the result will retain the date hierarchy.

As an aggregation
MIN(expression) is an aggregate function and returns a single aggregated result. This displays
as AGG(expression) in the viz.

As a comparison

MIN(expr1, expr2) compares the two values and returns a row-level value.

See also MAX.


PI
Syntax PI()
Output Number
Definition Returns the numeric constant pi: 3.14159...
Example PI() = 3.14159
Notes Useful for trig functions that take their input in radians. See also RADIANS.
POWER
Syntax POWER(number, power)
Output Number
Definition Raises the <number> to the specified <power>.
Example POWER(5,3) = 125
POWER([Temperature], 2)
Notes You can also use the ^ symbol, such as 5^3 = POWER(5,3) = 125

See also EXP, LOG, and SQUARE.


RADIANS
Syntax RADIANS(number)
Output Number (angle in radians)
Definition Converts the given <number> from degrees to radians.
Example RADIANS(180) = 3.14159
Notes The inverse function, DEGREES, takes an angle in radians and returns the angle in degrees.
ROUND
Syntax ROUND(number, [decimals])
Output Number
Definitio Rounds <number> to a specified number of digits.
n
The optional decimals argument specifies how many decimal points of precision to include in the
final result. If decimals is omitted, number is rounded to the nearest integer.
Example ROUND(1/3, 2) = 0.33
Notes Some databases, such as SQL Server, allow specification of a negative length, where -1 rounds
number to 10's, -2 rounds to 100's, and so on. This is not true of all databases. For example, it is
not true of Excel or Access.

Tip: Because ROUND may run into issues due to the underlying floating point representation of
numbers—such as 9.405 rounding to 9.40—it may be preferable to format the number to the
desired number of decimal points rather than rounding. Formatting 9.405 to two decimal places
will yield the expected 9.41.

See also CEILING and FLOOR.


SIGN
Syntax SIGN(number)
Output -1, 0, or 1
Definitio Returns the sign of a <number>: The possible return values are -1 if the number is negative, 0 if
n the number is zero, or 1 if the number is positive.
Example SIGN(AVG(Profit)) = -1
Notes See also ABS.
SIN
Syntax SIN(number)

The number argument is the angle in radians.


Output Number
Definition Returns the sine of an angle.
Example SIN(0) = 1.0
SIN(PI( )/4) = 0.707106781186548
Notes The inverse function, ASIN, takes the sine as the argument and returns the angle in radians.

See also PI. To convert an angle from degrees to radians, use RADIANS.
SQRT
Syntax SQRT(number)
Output Number
Definition Returns the square root of a <number>.
Example SQRT(25) = 5
Notes See also SQUARE.
SQUARE
Syntax SQUARE(number)
Output Number
Definition Returns the square of a <number>.
Example SQUARE(5) = 25
Notes See also SQRT and POWER.
TAN
Syntax TAN(number)
The number argument is the angle in radians.
Output Number
Definitio Returns the tangent of an angle.
n
Example TAN(PI ( )/4) = 1.0
Notes See also ATAN, ATAN2,COT, and PI. To convert an angle from degrees to radians,
use RADIANS.
ZN
Syntax ZN(expression)
Output Any, or o
Definitio Returns the <expression> if it is not null, otherwise returns zero.
n
Use this function to replace null values with zeros.
Example ZN(Grade) = 0
Notes This is a very useful function when using fields that may contain nulls in a calculation.
Wrapping the field with ZN can prevent errors caused by calculating with nulls.
String functions
ASCII
Syntax ASCII(string)
Output Number
Definition Returns the ASCII code for the first character of a <string>.
Example ASCII('A') = 65
Notes This is the inverse of the CHAR function.
CHAR
Syntax CHAR(number)
Output String
Definition Returns the character encoded by the ASCII code <number>.
Example CHAR(65) = 'A'
Notes This is the inverse of the ASCII function.
CONTAINS
Syntax CONTAINS(string, substring)
Output Boolean
Definitio Returns true if the given string contains the specified substring.
n
Example CONTAINS("Calculation", "alcu") = true
Notes See also the logical function(Link opens in a new window) IN as well as supported RegEx in
the additional functions documentation(Link opens in a new window).
ENDSWITH
Syntax ENDSWITH(string, substring)
Output Boolean
Definitio Returns true if the given string ends with the specified substring. Trailing white spaces are
n ignored.
Example ENDSWITH("Tableau", "leau") = true
Notes See also the supported RegEx in the additional functions documentation(Link opens in a new
window).
FIND
Syntax FIND(string, substring, [start])
Output Number
Definitio Returns the index position of substring in string, or 0 if the substring isn't found. The first
n character in the string is position 1.

If the optional numeric argument start is added, the function ignores any instances of substring
that appear before the starting position.
Example FIND("Calculation", "alcu") = 2
FIND("Calculation", "Computer") = 0
FIND("Calculation", "a", 3) = 7
FIND("Calculation", "a", 2) = 2
FIND("Calculation", "a", 8) = 0
Notes See also the supported RegEx in the additional functions documentation(Link opens in a new
window).
FINDNTH
Syntax FINDNTH(string, substring, occurrence)
Output Number
Definitio Returns the position of the nth occurrence of substring within the specified string, where n is
n defined by the occurrence argument.
Example FINDNTH("Calculation", "a", 2) = 7
Notes FINDNTH is not available for all data sources.

See also the supported RegEx in the additional functions documentation(Link opens in a new
window).
LEFT
Syntax LEFT(string, number)
Output String
Definition Returns the left-most <number> of characters in the string.
Example LEFT("Matador", 4) = "Mata"
Notes See also MID and RIGHT.
LEN
Syntax LEN(string)
Output Number
Definition Returns the length of the string.
Example LEN("Matador") = 7
Notes Not to be confused with the spatial function(Link opens in a new window) LENGTH.
LOWER
Syntax LOWER(string)
Output String
Definition Returns the provided <string> in all lowercase characters.
Example LOWER("ProductVersion") = "productversion"
Notes See also UPPER and PROPER.
LTRIM
Syntax LTRIM(string)
Output String
Definition Returns the provided <string> with any leading spaces removed.
Example LTRIM(" Matador ") = "Matador "
Notes See also RTRIM.
MAX
Syntax MAX(expression) or MAX(expr1, expr2)
Output Same data type as the argument, or NULL if any part of the argument is null.
Definitio Returns the maximum of the two arguments, which must be of the same data type.
n
MAX can also be applied to a single field as an aggregation.
Example MAX(4,7) = 7
MAX(#3/25/1986#, #2/20/2021#) = #2/20/2021#
MAX([Name]) = "Zander"
Notes For strings

MAX is usually the value that comes last in alphabetical order.

For database data sources, the MAX string value is highest in the sort sequence defined by the
database for that column.

For dates

For dates, the MAX is the most recent date. If MAX is an aggregation, the result will not have a
date hierarchy. If MAX is a comparison, the result will retain the date hierarchy.

As an aggregation

MAX(expression) is an aggregate function and returns a single aggregated result. This displays
as AGG(expression) in the viz.
As a comparison

MAX(expr1, expr2) compares the two values and returns a row-level value.

See also MIN.


MID
Syntax (MID(string, start, [length])
Output String
Definitio Returns a string starting at the specified start position. The first character in the string is position
n 1.

If the optional numeric argument length is added, the returned string includes only that number
of characters.
Example MID("Calculation", 2) = "alculation"
MID("Calculation", 2, 5) ="alcul"
Notes See also the supported RegEx in the additional functions documentation(Link opens in a new
window).
MIN
Syntax MIN(expression) or MIN(expr1, expr2)
Output Same data type as the argument, or NULL if any part of the argument is null.
Definitio Returns the minimum of the two arguments, which must be of the same data type.
n
MIN can also be applied to a single field as an aggregation.
Example MIN(4,7) = 4
MIN(#3/25/1986#, #2/20/2021#) = #3/25/1986#
MIN([Name]) = "Abebi"
Notes For strings

MIN is usually the value that comes first in alphabetical order.

For database data sources, the MIN string value is lowest in the sort sequence defined by the
database for that column.

For dates

For dates, the MIN is the earliest date. If MIN is an aggregation, the result will not have a date
hierarchy. If MIN is a comparison, the result will retain the date hierarchy.

As an aggregation

MIN(expression) is an aggregate function and returns a single aggregated result. This displays
as AGG(expression) in the viz.
As a comparison

MIN(expr1, expr2) compares the two values and returns a row-level value.

See also MAX.


PROPER
Syntax PROPER(string)
Output String
Definition Returns the provided <string> with the first letter of each word is capitalized and the
remaining letters are in lowercase.
Example PROPER("PRODUCT name") = "Product Name"
PROPER("darcy-mae") = "Darcy-Mae"
Notes Spaces and non-alphanumeric characters such as punctuation are treated as separators.

See also LOWER and UPPER.


Database PROPER is only available for some flat files and in extracts. If you need to use PROPER
limitations in a data source that doesn't otherwise support it, consider using an extract.
REPLACE
Syntax REPLACE(string, substring, replacement
Output String
Definitio Searches <string> for <substring> and replaces it with <replacement>. If <substring> is not found, the
n string is not changed.
Example REPLACE("Version 3.8", "3.8", "4x") = "Version 4x"
Notes See also REGEXP_REPLACE in the additional functions documentation(Link opens in a new
window).
RIGHT
Syntax RIGHT(string, number)
Output String
Definition Returns the right-most <number> of characters in the string.
Example RIGHT("Calculation", 4) = "tion"
Notes See also LEFT and MID.
RTRIM
Syntax RTRIM(string)
Output String
Definition Returns the provided <string> with any trailing spaces removed.
Example RTRIM(" Calculation ") = " Calculation"
Notes See also LTRIM and TRIM.
SPACE
Syntax SPACE(number)
Output String (specifically, just spaces)
Definition Returns a string that is composed of the specified number of repeated spaces.
Example SPACE(2) = " "

SPLIT
Syntax SPLIT(string, delimiter, token number)
Output String
Definition Returns a substring from a string, using a delimiter character to divide the string into a
sequence of tokens.
Example SPLIT ("a-b-c-d", "-", 2) = "b"
SPLIT ("a|b|c|d", "|", -2) = "c"
Notes The string is interpreted as an alternating sequence of delimiters and tokens. So for the
string abc-defgh-i-jkl, where the delimiter character is '-', the tokens are (1) abc, (2) defgh, (3) i,
and (4) jlk.

SPLIT returns the token corresponding to the token number. When the token number is
positive, tokens are counted starting from the left end of the string; when the token number is
negative, tokens are counted starting from the right.

See also supported REGEX in the additional functions documentation(Link opens in a new
window).
Database The split and custom split commands are available for the following data sources types:
limitations Tableau data extracts, Microsoft Excel, Text File, PDF File, Salesforce, OData, Microsoft
Azure Market Place, Google Analytics, Vertica, Oracle, MySQL, PostgreSQL, Teradata,
Amazon Redshift, Aster Data, Google Big Query, Cloudera Hadoop Hive, Hortonworks
Hive, and Microsoft SQL Server.

Some data sources impose limits on splitting strings. See SPLIT function limitations later in
this topic.
STARTSWITH
Syntax STARTSWITH(string, substring)
Output Boolean
Definitio Returns true if string starts with substring. Leading white spaces are ignored.
n
Example STARTSWITH("Matador, "Ma") = TRUE
Notes See also CONTAINS, as well as supported REGEX in the additional functions
documentation(Link opens in a new window).
TRIM
Syntax TRIM(string)
Output String
Definition Returns the provided <string> with leading and trailing spaces removed.
Example TRIM(" Calculation ") = "Calculation"
Notes See also LTRIM and RTRIM.
UPPER
Syntax UPPER(string)
Output String
Definition Returns the provided <string> in all uppercase characters.
Example UPPER("Calculation") = "CALCULATION"
Notes See also PROPER and LOWER.

Table calculations
FIRST( )

Returns the number of rows from the current row to the first row in the partition. For
example, the view below shows quarterly sales. When FIRST() is computed within the
Date partition, the offset of the first row from the second row is -1.

Example

When the current row index is 3, FIRST() = -2.


INDEX( )

Returns the index of the current row in the partition, without any sorting with regard to
value. The first row index starts at 1. For example, the table below shows quarterly sales.
When INDEX() is computed within the Date partition, the index of each row is 1, 2, 3,
4..., etc.
Example

For the third row in the partition, INDEX() = 3.


LAST( )

Returns the number of rows from the current row to the last row in the partition. For
example, the table below shows quarterly sales. When LAST() is computed within the
Date partition, the offset of the last row from the second row is 5.

Example

When the current row index is 3 of 7, LAST() = 4.


LOOKUP(expression, [offset])

Returns the value of the expression in a target row, specified as a relative offset from the
current row. Use FIRST() + n and LAST() - n as part of your offset definition for a target
relative to the first/last rows in the partition. If offset is omitted, the row to compare to
can be set on the field menu. This function returns NULL if the target row cannot be
determined.
The view below shows quarterly sales. When LOOKUP (SUM(Sales), 2) is computed within
the Date partition, each row shows the sales value from 2 quarters into the future.

Example

LOOKUP(SUM([Profit]), FIRST()+2) computes the SUM(Profit) in the third row of the


partition.
MODEL_EXTENSION_BOOL (model_name, arguments,
expression)

Returns the boolean result of an expression as calculated by a named model deployed on


a TabPy external service.

Model_name is the name of the deployed analytics model you want to use.

Each argument is a single string that sets the input values that the deployed model
accepts, and is defined by the analytics model.

Use expressions to define the values that are sent from Tableau to the analytics model.
Be sure to use aggregation functions (SUM, AVG, etc.) to aggregate the results.
When using the function, the data types and order of the expressions must match that of
the input arguments.

Example

MODEL_EXTENSION_BOOL ("isProfitable","inputSales", "inputCosts", SUM([Sales]), SUM([Costs]))


MODEL_EXTENSION_INT (model_name, arguments, expression)

Returns an integer result of an expression as calculated by a named model deployed on a


TabPy external service.

Model_name is the name of the deployed analytics model you want to use.

Each argument is a single string that sets the input values that the deployed model
accepts, and is defined by the analytics model.

Use expressions to define the values that are sent from Tableau to the analytics model.
Be sure to use aggregation functions (SUM, AVG, etc.) to aggregate the results.

When using the function, the data types and order of the expressions must match that of
the input arguments.

Example

MODEL_EXTENSION_INT ("getPopulation", "inputCity", "inputState", MAX([City]), MAX ([State]))


MODEL_EXTENSION_REAL (model_name, arguments,
expression)

Returns a real result of an expression as calculated by a named model deployed on a


TabPy external service.

Model_name is the name of the deployed analytics model you want to use.

Each argument is a single string that sets the input values that the deployed model
accepts, and is defined by the analytics model.

Use expressions to define the values that are sent from Tableau to the analytics model.
Be sure to use aggregation functions (SUM, AVG, etc.) to aggregate the results.

When using the function, the data types and order of the expressions must match that of
the input arguments.

Example
MODEL_EXTENSION_REAL ("profitRatio", "inputSales", "inputCosts", SUM([Sales]), SUM([Costs]))
MODEL_EXTENSION_STRING (model_name, arguments,
expression)

Returns the string result of an expression as calculated by a named model deployed on a


TabPy external service.

Model_name is the name of the deployed analytics model you want to use.

Each argument is a single string that sets the input values that the deployed model
accepts, and is defined by the analytics model.

Use expressions to define the values that are sent from Tableau to the analytics model.
Be sure to use aggregation functions (SUM, AVG, etc.) to aggregate the results.

When using the function, the data types and order of the expressions must match that of
the input arguments.

Example

MODEL_EXTENSION_STR ("mostPopulatedCity", "inputCountry", "inputYear", MAX ([Country]),


MAX([Year]))
MODEL_PERCENTILE(target_expression,
predictor_expression(s))

Returns the probability (between 0 and 1) of the expected value being less than or equal
to the observed mark, defined by the target expression and other predictors. This is the
Posterior Predictive Distribution Function, also known as the Cumulative Distribution
Function (CDF).

This function is the inverse of MODEL_QUANTILE. For information on predictive


modeling functions, see How Predictive Modeling Functions Work in Tableau.

Example

The following formula returns the quantile of the mark for sum of sales, adjusted for
count of orders.

MODEL_PERCENTILE(SUM([Sales]), COUNT([Orders]))
MODEL_QUANTILE(quantile, target_expression,
predictor_expression(s))
Returns a target numeric value within the probable range defined by the target
expression and other predictors, at a specified quantile. This is the Posterior Predictive
Quantile.

This function is the inverse of MODEL_PERCENTILE. For information on predictive


modeling functions, see How Predictive Modeling Functions Work in Tableau.

Example

The following formula returns the median (0.5) predicted sum of sales, adjusted for
count of orders.

MODEL_QUANTILE(0.5, SUM([Sales]), COUNT([Orders]))


PREVIOUS_VALUE(expression)

Returns the value of this calculation in the previous row. Returns the given expression if
the current row is the first row of the partition.

Example

SUM([Profit]) * PREVIOUS_VALUE(1) computes the running product of SUM(Profit).


RANK(expression, ['asc' | 'desc'])

Returns the standard competition rank for the current row in the partition. Identical
values are assigned an identical rank. Use the optional 'asc' | 'desc' argument to specify
ascending or descending order. The default is descending.

With this function, the set of values (6, 9, 9, 14) would be ranked (4, 2, 2, 1).

Nulls are ignored in ranking functions. They are not numbered and they do not count
against the total number of records in percentile rank calculations.

For information on different ranking options, see Rank calculation.

Example

The following image shows the effect of the various ranking functions (RANK,
RANK_DENSE, RANK_MODIFIED, RANK_PERCENTILE, and RANK_UNIQUE) on a
set of values. The data set contains information on 14 students (StudentA through
StudentN); the Age column shows the current age of each student (all students are
between 17 and 20 years of age). The remaining columns show the effect of each rank
function on the set of age values, always assuming the default order (ascending or
descending) for the function.
RANK_DENSE(expression, ['asc' | 'desc'])

Returns the dense rank for the current row in the partition. Identical values are assigned
an identical rank, but no gaps are inserted into the number sequence. Use the
optional 'asc' | 'desc' argument to specify ascending or descending order. The default is
descending.

With this function, the set of values (6, 9, 9, 14) would be ranked (3, 2, 2, 1).

Nulls are ignored in ranking functions. They are not numbered and they do not count
against the total number of records in percentile rank calculations.

For information on different ranking options, see Rank calculation.

RANK_MODIFIED(expression, ['asc' | 'desc'])

Returns the modified competition rank for the current row in the partition. Identical
values are assigned an identical rank. Use the optional 'asc' | 'desc' argument to specify
ascending or descending order. The default is descending.

With this function, the set of values (6, 9, 9, 14) would be ranked (4, 3, 3, 1).

Nulls are ignored in ranking functions. They are not numbered and they do not count
against the total number of records in percentile rank calculations.

For information on different ranking options, see Rank calculation.


RANK_PERCENTILE(expression, ['asc' | 'desc'])

Returns the percentile rank for the current row in the partition. Use the optional 'asc' |
'desc' argument to specify ascending or descending order. The default is ascending.

With this function, the set of values (6, 9, 9, 14) would be ranked (0.00, 0.67, 0.67,
1.00).

Nulls are ignored in ranking functions. They are not numbered and they do not count
against the total number of records in percentile rank calculations.

For information on different ranking options, see Rank calculation.

RANK_UNIQUE(expression, ['asc' | 'desc'])

Returns the unique rank for the current row in the partition. Identical values are
assigned different ranks. Use the optional 'asc' | 'desc' argument to specify ascending or
descending order. The default is descending.

With this function, the set of values (6, 9, 9, 14) would be ranked (4, 2, 3, 1).

Nulls are ignored in ranking functions. They are not numbered and they do not count
against the total number of records in percentile rank calculations.

For information on different ranking options, see Rank calculation.

RUNNING_AVG(expression)

Returns the running average of the given expression, from the first row in the partition
to the current row.

The view below shows quarterly sales. When RUNNING_AVG(SUM([Sales]) is computed


within the Date partition, the result is a running average of the sales values for each
quarter.
Example

RUNNING_AVG(SUM([Profit])) computes the running average of SUM(Profit).


RUNNING_COUNT(expression)

Returns the running count of the given expression, from the first row in the partition to
the current row.

Example

RUNNING_COUNT(SUM([Profit])) computes the running count of SUM(Profit).


RUNNING_MAX(expression)

Returns the running maximum of the given expression, from the first row in the
partition to the current row.
Example

RUNNING_MAX(SUM([Profit])) computes the running maximum of SUM(Profit).


RUNNING_MIN(expression)

Returns the running minimum of the given expression, from the first row in the
partition to the current row.
Example

RUNNING_MIN(SUM([Profit])) computes the running minimum of SUM(Profit).


RUNNING_SUM(expression)

Returns the running sum of the given expression, from the first row in the partition to
the current row.
Example

RUNNING_SUM(SUM([Profit])) computes the running sum of SUM(Profit)


SIZE()

Returns the number of rows in the partition. For example, the view below shows
quarterly sales. Within the Date partition, there are seven rows so the Size() of the Date
partition is 7.
Example

SIZE() = 5 when the current partition contains five rows.

Logical functions
AND
Syntax <expr1> AND <expr2>
Definitio Performs a logical conjunction on two expressions. (If both sides are true, the logical test
n returns true.)
Output Boolean (true or false)
Example IF [Season] = "Spring" AND "[Season] = "Fall"
THEN "It's the apocalypse and footwear doesn't matter"
END

"If both (Season = Spring) and (Season = Fall) are true simultaneously, then return It's the
apocalypse and footwear doesn't matter."
Notes Often used with IF and IIF. See also NOT and OR.

If both expressions are TRUE (that is, not FALSE or NULL), then the result is TRUE. If either
expression is NULL, then the result is NULL. In all other cases, the result is FALSE.

If you create a calculation in which the result of an AND comparison is displayed on a


worksheet, Tableau displays TRUE and FALSE. If you would like to change this, use the Format
area in the format dialog.

Note: The AND operator employs short circuit evaluation. This means that if the first expression
is evaluated to be FALSE, then the second expression is not evaluated at all. This can be helpful
if the second expression results in an error when the first expression is FALSE, because the
second expression in this case is never evaluated.
CASE
Syntax CASE <expression>
WHEN <value1> THEN <then1>
WHEN <value2> THEN <then2>
...
[ELSE <default>]
END
Output Depends on data type of the <then> values.
Definitio Evaluates the expression and compares it to the specified options (<value1>, <value2>, etc.). When
n a value that matches expression is encountered, CASE returns the corresponding return. If no
match is found, the (optional) default is returned. If there is no default and no values match,
then Null is returned.
Example CASE [Season]
WHEN 'Summer' THEN 'Sandals'
WHEN 'Winter' THEN 'Boots'
ELSE 'Sneakers'
END
"Look at the Season field. If the value is Summer, then return Sandals. If the value is Winter,
then return Boots. If none of the options in the calculation match what is in the Season field,
return a Sneakers."
Notes See also IF and IIF.

Used with WHEN, THEN, ELSE, and END.

Tip: Many times you can use a group to get the same results as a complicated CASE function,
or use CASE to replace native grouping functionality, such as in the previous example. You
may want to test which is more performant for your scenario.
ELSE
Syntax CASE <expression>
WHEN <value1> THEN <then1>
WHEN <value2> THEN <then2>
...
[ELSE <default>]
END
Definitio An optional piece of an IF or CASE expression used to specify a default value to return if none
n of the tested expressions are true.
Example IF [Season] = "Summer" THEN 'Sandals'
ELSEIF [Season] = "Winter" THEN 'Boots'
ELSE 'Sneakers'
END
CASE [Season]
WHEN 'Summer' THEN 'Sandals'
WHEN 'Winter' THEN 'Boots'
ELSE 'Sneakers'
END
Notes Used with CASE, WHEN, IF, ELSEIF, THEN, and END

ELSE is optional with CASE and IF. In a calculation where ELSE is not specified, if none of
the <test>are true, the overall calculation will return null.

ELSE does not require a condition (such as [Season] = "Winter") and can be thought of as a form of
null handling.
ELSEIF
Syntax [ELSEIF <test2> THEN <then2>]
Definitio An optional piece of an IF expression used to specify additional conditions beyond the initial IF.
n
Example IF [Season] = "Summer" THEN 'Sandals'
ELSEIF [Season] = "Winter" THEN 'Boots'
ELSEIF [Season] = "Spring" THEN 'Sneakers'
ELSEIF [Season] = "Autumn" THEN 'Sneakers'
ELSE 'Bare feet'
END
Notes Used with IF, THEN, ELSE, and END

ELSEIF can be thought of as additional IF clauses. ELSEIF is optional and can be repeated
multiple times.

Unlike ELSE, ELSEIF requires a condition (such as [Season] = "Winter").


END
Definitio Used to close an IF or CASE expression.
n
Example IF [Season] = "Summer" THEN 'Sandals'
ELSEIF [Season] = "Winter" THEN 'Boots'
ELSE 'Sneakers'
END

"If Season = Summer, then return Sandals. If not, look at the next expression. If Season =
Winter, then return Boots. If neither of the expressions are true, return Sneakers."

CASE [Season]
WHEN 'Summer' THEN 'Sandals'
WHEN 'Winter' THEN 'Boots'
ELSE 'Sneakers'
END

"Look at the Season field. If the value is Summer, then return Sandals. If the value is Winter,
then return Boots. If none of the options in the calculation match what is in the Season field,
return a Sneakers."
Notes Used with CASE, WHEN, IF, ELSEIF, THEN, and ELSE.
IF
Syntax IF <test1> THEN <then1>
[ELSEIF <test2> THEN <then2>...]
[ELSE <default>]
END
Output Depends on data type of the <then> values.
Definitio Tests a series of expressions and returns the <then> value for the first true <test>.
n
Example IF [Season] = "Summer" THEN 'Sandals'
ELSEIF [Season] = "Winter" THEN 'Boots'
ELSE 'Sneakers'
END

"If Season = Summer, then return Sandals. If not, look at the next expression. If Season =
Winter, then return Boots. If neither of the expressions are true, return Sneakers."
Notes See also IF and IIF.
Used with ELSEIF, THEN, ELSE, and END
IFNULL
Syntax IFNULL(expr1, expr2)
Output Depends on the data type of the <expr> values.
Definitio Returns <expr1> if it's non-null, otherwise returns <expr2>.
n
Example IFNULL([Assigned Room], "TBD")

"If the Assigned Room field isn't null, return its value. If the Assigned room field is null, return
TBD instead."
Notes Compare with ISNULL. IFNULL always returns a value. ISNULL returns a boolean (true or
false).

See also ZN.


IIF
Syntax IIF(<test>, <then>, <else>, [<unknown>])
Output Depends on the data type of the values in the expression.
Definitio Checks whether a condition is met (<test>), and returns <then>if the test is true, <else> if the test is
n false, and an optional value for <unknown> if the test is null. If the optional unknown isn't
specified, IIF returns null.
Example IIF([Season] = 'Summer', 'Sandals', 'Other footwear')

"If Season = Summer, then return Sandals. If not, return Other footwear"

IIF([Season] = 'Summer', 'Sandals',


IIF('Season' = 'Winter', 'Boots', 'Other footwear')
)

"If Season = Summer, then return Sandals. If not, look at the next expression. If Season =
Winter, then return Boots. If neither are true, return Sneakers."

IIF('Season' = 'Summer', 'Sandals',


IIF('Season' = 'Winter', 'Boots',
IIF('Season' = 'Spring', 'Sneakers', 'Other footwear')
)
)

"If Season = Summer, then return Sandals. If not, look at the next expression. If Season =
Winter, then return Boots. If none of the expressions are true, return Sneakers."
Notes See also IF andCASE.

doesn't have an equivalent to ELSEIF (like IF) or repeated WHEN clauses (like CASE). Instead,
IIF
multiple tests can be evaluated sequentially by nesting IIF statements as the <unknown> element.
The first (outermost) true is returned.

That is to say, in the calculation below, the result will be Red, not Orange, because the
expression stops being evaluated as soon as A=A is evaluated as true:

IIF('A' = 'A', 'Red', IIF('B' = 'B', 'Orange', IIF('C' = 'D', 'Yellow', 'Green')))
IN
Syntax <expr1> IN <expr2>
Output Boolean (true or false)
Definition Returns TRUE if any value in <expr1> matches any value in <expr2>.
Example SUM([Cost]) IN (1000, 15, 200)

"Is the value of the Cost field 1000, 15, or 200?"

[Field] IN [Set]

"Is the value of the field present in the set?"


Notes The values in <expr2> can be a set, list of literal values, or combined field.

See also WHEN.


ISDATE
Syntax ISDATE(string)
Output Boolean (true or false)
Definitio Returns true if a <string> is a valid date. The input expression must be a string (text) field.
n
Example ISDATE("2018-09-22")

"Is the string 2018-09-22 a properly formatted date?"


Notes What is considered a valid date depends on the locale(Link opens in a new window) of the
system evaluating the calculation. For example:

In the USA:

 ISDATE("2018-09-22") = TRUE
 ISDATE("2018-22-09") = FALSE

In the UK:

 ISDATE("2018-09-22") = FALSE
 ISDATE("2018-22-09") = TRUE
ISNULL
Syntax ISNULL(expression)
Output Boolean (true or false)
Definition Returns true if the <expression> is NULL (does not contain valid data).
Example ISNULL([Assigned Room])

"Is the Assigned Room field null?"


Notes Compare with IFNULL. IFNULL always returns a value. ISNULL returns a boolean.

See also ZN.


MAX
Syntax MAX(expression) or MAX(expr1, expr2)
Output Same data type as the argument, or NULL if any part of the argument is null.
Definitio Returns the maximum of the two arguments, which must be of the same data type.
n
MAX can also be applied to a single field as an aggregation.
Example MAX(4,7) = 7
MAX(#3/25/1986#, #2/20/2021#) = #2/20/2021#
MAX([Name]) = "Zander"
Notes For strings

MAX is usually the value that comes last in alphabetical order.

For database data sources, the MAX string value is highest in the sort sequence defined by the
database for that column.

For dates

For dates, the MAX is the most recent date. If MAX is an aggregation, the result will not have a
date hierarchy. If MAX is a comparison, the result will retain the date hierarchy.

As an aggregation

MAX(expression) is an aggregate function and returns a single aggregated result. This displays
as AGG(expression) in the viz.

As a comparison

MAX(expr1, expr2) compares the two values and returns a row-level value.

See also MIN.


MIN
Syntax MIN(expression) or MIN(expr1, expr2)
Output Same data type as the argument, or NULL if any part of the argument is null.
Definitio Returns the minimum of the two arguments, which must be of the same data type.
n

MIN can also be applied to a single field as an aggregation.


Example MIN(4,7) = 4
MIN(#3/25/1986#, #2/20/2021#) = #3/25/1986#
MIN([Name]) = "Abebi"
Notes For strings

MIN is usually the value that comes first in alphabetical order.

For database data sources, the MIN string value is lowest in the sort sequence defined by the
database for that column.

For dates

For dates, the MIN is the earliest date. If MIN is an aggregation, the result will not have a date
hierarchy. If MIN is a comparison, the result will retain the date hierarchy.

As an aggregation

MIN(expression) is an aggregate function and returns a single aggregated result. This displays
as AGG(expression) in the viz.

As a comparison

MIN(expr1, expr2) compares the two values and returns a row-level value.

See also MAX.


NOT
Syntax NOT <expression>
Output Boolean (true or false)
Definition Performs logical negation on an expression.
Example IF NOT [Season] = "Summer"
THEN 'Don't wear sandals'
ELSE 'Wear sandals'
END

"If Season doesn't equal Summer, then return Don't wear sandals. If not, return Wear sandals."
Notes Often used with IF and IIF. See also DATE and OR.
OR
Syntax <expr1> OR <expr2>
Output Boolean (true or false)
Definitio Performs a logical disjunction on two expressions.
n
Example IF [Season] = "Spring" OR [Season] = "Fall"
THEN "Sneakers"
END

"If either (Season = Spring) or (Season = Fall) is true, then return Sneakers."
Notes Often used with IF and IIF. See also DATE and NOT.

If either expression is TRUE, then the result is TRUE. If both expressions are FALSE, then the
result is FALSE. If both expressions are NULL, then the result is NULL.

If you create a calculation which displays the result of an OR comparison on a worksheet,


Tableau displays TRUE and FALSE. If you would like to change this, use the Format area in
the format dialog.

Note: The OR operator employs short circuit evaluation. This means that if the first expression
is evaluated to be TRUE, then the second expression is not evaluated at all. This can be helpful if
the second expression results in an error when the first expression is TRUE, because the second
expression in this case is never evaluated.
THEN
Syntax IF <test1> THEN <then1>
[ELSEIF <test2> THEN <then2>...]
[ELSE <default>]
END
Definitio A required part of an IF, ELSEIF, or CASE expression, used to define what result to return if a
n specific value or test is true.
Example IF [Season] = "Summer" THEN 'Sandals'
ELSEIF [Season] = "Winter" THEN 'Boots'
ELSE 'Sneakers'
END

"If Season = Summer, then return Sandals. If not, look at the next expression. If Season =
Winter, then return Boots. If neither of the expressions are true, return Sneakers."

CASE [Season]
WHEN 'Summer' THEN 'Sandals'
WHEN 'Winter' THEN 'Boots'
ELSE 'Sneakers'
END

"Look at the Season field. If the value is Summer, then return Sandals. If the value is Winter,
then return Boots. If none of the options in the calculation match what is in the Season field,
return a Sneakers."
Notes Used with CASE, WHEN, IF, ELSEIF, THEN, ELSE, and END
WHEN
Syntax CASE <expression>
WHEN <value1> THEN <then1>
WHEN <value2> THEN <then2>
...
[ELSE <default>]
END
Definitio A required part of a CASE expression. Finds the first <value> that matches <expression> and
n returns the corresponding <then>.
Example CASE [Season]
WHEN 'Summer' THEN 'Sandals'
WHEN 'Winter' THEN 'Boots'
ELSE 'Sneakers'
END

"Look at the Season field. If the value is Summer, then return Sandals. If the value is Winter,
then return Boots. If none of the options in the calculation match what is in the Season field,
return a Sneakers."
Notes Used with CASE, THEN, ELSE, and END.

CASE also supports WHEN IN construction, such as:

CASE <expression>
WHEN IN <set1> THEN <then1>
WHEN IN <combinedfield> THEN <then2>
...
ELSE <default>
END

The values that WHEN IN compare to must be a set, list of literal values, or combined field. See
also IN.
ZN
Syntax ZN(expression)
Output Depends on the data type of the <expression>, or 0.
Definitio Returns <expression> if it isn't null, otherwise returns zero.
n
Example ZN([Test Grade])

"If the test grade isn't null, return its value. If the test grade is null, return 0."
Notes ZN is a specialized case of IFNULL where alternative if the expression is null is always 0 rather
than being specified in the calculation.

ZN is especially useful when performing additional calculations and a null would render the
entire calculation null. However, use caution interpreting these results as null is not always
synonymous with 0 and could represent missing data.

See also ISNULL.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy