Tableau Calculation
Tableau Calculation
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.
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
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.
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.
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 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
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.
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
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.
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
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
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
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
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_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_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)
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
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).
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.
Example
The following formula returns the median (0.5) predicted sum of sales, adjusted for
count of orders.
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
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.
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.
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.
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.
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.
RUNNING_AVG(expression)
Returns the running average of the given expression, from the first row in the partition
to the current row.
Returns the running count of the given expression, from the first row in the partition to
the current row.
Example
Returns the running maximum of the given expression, from the first row in the
partition to the current row.
Example
Returns the running minimum of the given expression, from the first row in the
partition to the current row.
Example
Returns the running sum of the given expression, from the first row in the partition to
the current row.
Example
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
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.
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.
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.
"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).
"If Season = Summer, then return Sandals. If not, return 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."
"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)
[Field] IN [Set]
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])
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.
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.
"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.
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 <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.