Custom calculation function reference
This page provides a complete reference of all supported functions for custom calculations in AI/BI dashboards. For information about how to use custom calculations, see What are custom calculations?.
Aggregate functions
All calculated measures must be aggregated. The following aggregation operations are supported:
Use the DISTINCT keyword in aggregate functions to include only unique values in the aggregation. Additionally, the FILTER(WHERE condition) clause can be appended to any aggregate function to limit the values that are included in the calculation.
Function | Description |
|---|---|
Returns | |
Returns some value of | |
Returns the estimated number of distinct values in | |
approx_percentile ([ALL | DISTINCT] expr, percentile [, accuracy]) | Returns the approximate percentile value of |
Returns the calculated mean in a column or expression. | |
Returns | |
Returns the Pearson correlation coefficient between | |
Returns the number of rows in a group. | |
Returns the number of unique rows in a group. | |
Returns the count of rows that satisfy a given condition. | |
Returns the first value of | |
Returns the first value of | |
Returns the last value of | |
Returns the last value of | |
Returns the concatenation of non-null values in the group. | |
Returns the maximum value in a column or expression. | |
Returns the value of | |
Returns the calculated mean in a column or expression. | |
Returns the median of a set of values. | |
Returns the minimum value in a column or expression. | |
Returns the value of | |
Returns the most frequent value for | |
Returns the exact percentile value of | |
Returns the approximate percentile value of | |
Returns the slope of the linear regression line for non-null pairs in a group. | |
Returns | |
Returns the standard deviation of a set of values. | |
Returns the standard deviation of a set of values. | |
Returns the population standard deviation of a set of values. | |
Returns the sample standard deviation of a set of values. | |
Returns the concatenation of non-null string values in the group. | |
Returns the total of values in a column or expression. | |
Returns the variance of a set of values. |
Arithmetic operations
You can combine expressions with the following arithmetic operations:
Operation | Description |
|---|---|
Returns the remainder of dividing | |
Returns the product of two expressions. | |
Returns the sum of | |
Returns the value of the expression. | |
Returns the difference when subtracting | |
Returns the negated value of the expression. | |
Returns the result of dividing the dividend by the divisor. | |
Returns the integral part of the division of | |
Returns the absolute value of the numeric expression. | |
Returns the inverse cosine (arc cosine) of | |
Returns the inverse sine (arc sine) of | |
Returns | |
Returns the smallest integer not smaller than | |
Returns the cosine of | |
Returns e raised to the power of | |
Returns the largest integer not greater than | |
Returns the natural logarithm of the expression. | |
Returns the logarithm of | |
Returns the base-10 logarithm of the expression. | |
Returns the remainder of dividing | |
Returns | |
Returns the value of pi. | |
Returns the positive value of | |
Returns the result of | |
Converts degrees to radians. | |
Returns a random value with uniform distribution in the range from 0 (inclusive) to 1 (exclusive). | |
Returns | |
Returns the sign of the numeric expression. | |
Returns the sine of | |
Returns the square root of | |
Adds two values. If an error occurs, returns | |
Divides the dividend by the divisor. If an error occurs, returns | |
Multiplies two numbers. If an error occurs, returns | |
Subtracts | |
Returns 0 if |
Boolean functions and operators
Custom calculations support basic comparison and Boolean operators. The following operators and functions are supported:
Operation | Description |
|---|---|
Returns | |
Logical not. | |
Returns the bitwise AND of | |
Returns | |
Returns same result as the equal operator for non-null operands, but returns | |
Returns | |
Returns | |
Returns | |
Returns | |
Returns | |
Returns | |
Returns | |
Returns the bitwise exclusive OR of | |
Returns the bitwise OR of | |
Returns | |
Returns the bitwise NOT of | |
Returns | |
Tests whether | |
Returns | |
Tests whether | |
Returns | |
Returns | |
Returns | |
Returns | |
Logical not (prefix operator). Can also be used as | |
Returns | |
Returns | |
Returns | |
Returns |
Cast functions
Use the following functions to cast values to a specified type:
Function | Description |
|---|---|
Casts the value | |
Casts the value | |
Casts the value | |
Casts the value | |
Casts the value | |
Casts the value | |
Casts the value | |
Casts the value | |
Casts the value | |
Casts the value | |
Casts the value | |
Converts the | |
Converts the | |
Casts the value | |
Parses the |
Date, timestamp, and interval functions
Use the following functions to work with dates, timestamps, and intervals:
Function | Description |
|---|---|
Returns the date that is | |
Returns the current date. | |
Returns the current date. | |
Returns the current timestamp. | |
Returns the date that is | |
Returns the number of days from | |
Converts a timestamp to a string in the format | |
Extracts a specific part, such as year, month, or day, from a date or timestamp. | |
Returns the date that is | |
Truncates a date or timestamp to a specified unit, such as year or month. | |
Adds the specified time interval to a date or timestamp. | |
Returns the number of days from | |
Returns the day of the month from the date or timestamp. | |
Returns the name of the day of the week from the date or timestamp. | |
Returns the day of the month from the date or timestamp. | |
Returns the day of the week from the date or timestamp (1 = Sunday, 7 = Saturday). | |
Returns the day of the year from the date or timestamp. | |
Extracts a part of the date or timestamp. | |
Converts the number of seconds from Unix epoch to a timestamp. | |
Interprets the given timestamp as UTC and converts to the given time zone. | |
Returns the current timestamp. | |
Returns the hour component of the timestamp. | |
Returns the last day of the month which the date or timestamp belongs to. | |
Creates a date from year, month, and day fields. | |
make_timestamp(year, month, day, hour, min, sec [, timezone]) | Creates a timestamp from year, month, day, hour, minute, second, and optionally timezone fields. |
Returns the minute component of the timestamp. | |
Returns the month component of the date or timestamp. | |
Returns the number of months between | |
Returns the first date which is later than | |
Returns the current timestamp. | |
Returns the quarter of the year for the date or timestamp (1 to 4). | |
Returns the second component of the timestamp. | |
Returns the difference between two timestamps measured in units. | |
Creates a timestamp from the number of microseconds since Unix epoch. | |
Creates a timestamp from the number of milliseconds since Unix epoch. | |
Creates a timestamp from the number of seconds since Unix epoch. | |
Adds the specified time interval to a timestamp. | |
Returns the difference between two timestamps measured in units. | |
Converts the | |
Converts the | |
Returns the Unix timestamp of the given time. | |
Interprets the given timestamp in the given time zone and converts to UTC. | |
Returns | |
Returns the number of microseconds since Unix epoch. | |
Returns the number of milliseconds since Unix epoch. | |
Returns the number of seconds since Unix epoch. | |
Returns the Unix timestamp of the given time. | |
Returns the day of the week from the date or timestamp (0 = Monday, 6 = Sunday). | |
Returns the week of the year from the date or timestamp. | |
Returns the year component of the date or timestamp. |
String functions
Use the following functions to transform strings. To transform datetime strings, see Cast functions.
Function | Description |
|---|---|
Converts the argument to a base64 string. | |
Returns the character at the supplied UTF-16 code point. | |
Returns the position of the first occurrence of | |
Returns the concatenation of the arguments. | |
Returns the concatenation of strings separated by | |
Returns | |
Converts the timestamp | |
Translates binary | |
Returns | |
Returns the index (1-based) of the given string in the comma-delimited list. | |
Formats | |
Returns a formatted string from printf-style format strings. | |
Converts | |
Returns | |
Returns the position of the first occurrence of | |
Returns | |
Returns the leftmost | |
Returns the length of the string or binary expression. | |
Returns the length of the string or binary expression. | |
Returns the Levenshtein distance between the two given strings. | |
Returns the position of the first occurrence of | |
Returns | |
Returns | |
Removes leading characters from | |
Returns an MD5 128-bit checksum as a hex string. | |
Extracts a part from | |
Returns the position of the first occurrence of | |
Returns a formatted string from printf-style format strings. | |
Returns the number of times the regular expression | |
Extracts a group that matches | |
Returns the position of the first match of | |
Replaces all substrings of | |
Returns the substring that matches the regular expression | |
Returns the string that repeats | |
Replaces all occurrences of | |
Returns | |
Returns the rightmost | |
Returns | |
Returns the SHA-2 family of hash functions. | |
Splits | |
Returns | |
Returns the substring of | |
Returns the substring of | |
Returns the substring before | |
Converts | |
Converts string | |
Translates | |
Removes leading and trailing characters from | |
Returns | |
Returns | |
Encodes |
Miscellaneous functions
The following functions are also supported:
Function | Description |
|---|---|
Calculates values across time ranges or other ordered sets for measures. | |
Returns | |
Returns | |
Returns the first non-null argument. | |
decode(expr, search, result [, search, result]... [, default]) | Compares |
Extracts a JSON object from | |
Returns the greatest value of all parameters. | |
Returns a hash value of the arguments. | |
Returns | |
Returns | |
Returns | |
Returns the number of elements in the outermost JSON array. | |
Returns the least value of all parameters. | |
Returns monotonically increasing 64-bit integers. | |
Returns | |
Returns | |
Returns | |
Returns the schema in the DDL format of the JSON string. |