Math Functions in Calculated Fields

Math functions perform common mathematical operations.

SUM 

Evaluates to the sum of all numeric arguments. Strings are parsed into numbers if possible, unparseable strings or other values evaluate to zero.

# Infix operator usage: arg1 + arg2
# Examples
$serialize_ms + $scan_ms + $publish_ms
1.0 + 5 + "2.3"

# Function usage: SUM(arg1, arg2, ...)
# Examples
SUM($serialize_ms, $scan_ms, $publish_ms)
SUM(1.0, 5, "2.3")

SUB 

Evaluates to the first argument subtracted by the second, or arg1 - arg2. Strings are parsed into numbers if possible, unparseable strings or other values evaluate to zero.

# Infix operator usage: arg1 - arg2
# Examples
$serialization_ms - 100
$total_ms - ($local_ms + $merge_ms + $serialize_ms)

# Function usage: SUB(arg1, arg2)
# Examples
SUB($serialization_ms, 100)
SUB($total_ms, SUM($local_ms, $merge_ms, $serialize_ms))

MUL 

Multiplies all numeric arguments and returns the product. Strings are parsed into numbers if possible, unparseable strings or other values evaluate to zero.

# Infix operator usage: arg1 * arg2
# Examples
$count * $time_per_item
100 * ($json_decode_ms / $total_ms)

# Function usage: MUL(arg1, arg2, ...)
# Examples
MUL($count, $time_per_item)
MUL(100, DIV($json_decode_ms, $total_ms))

DIV 

Divides the first argument by the second, or arg1 / arg2. Strings are parsed into numbers if possible, unparseable strings or other values evaluate to zero. A division by zero evaluates to null.

# Infix operator usage: arg1 / arg2
# Examples
$io_bytes_read / 1024
$total_ms / $rows_examined
$json_parse_time_ms / $total_request_time_ms

# Function usage: DIV(arg1, arg2)
# Examples
DIV($io_bytes_read, 1024)
DIV($total_ms, $rows_examined)
DIV($json_parse_time_ms, $total_request_time_ms)

MOD 

Computes the remainder of arg1 / arg2. Strings are parsed into floats if possible, unparseable strings or other values evaluate to zero. Evaluates to null if arg2 is zero.

# Infix operator usage: arg1 % arg2
# Examples
15 % 12  # 3
5.5 % 4  # 1.5
6 % 5.5  # 0.5

# Function usage: MOD(arg1, arg2)
# Examples
MOD(15, 12)  # 3
MOD(5.5, 4)  # 1.5
MOD(6, 5.5)  # 0.5

MIN 

Evaluates to the smallest argument of the same type as the first non-empty argument. “Smallest” means the smaller, if numeric, or lexicographically first, if a string.

# Usage: MIN(arg1, arg2, ...)
# Examples
MIN($memory_inuse_local, $memory_inuse_merge, $memory_inuse_fetch)

MAX 

Evaluates to the largest argument of the same type as the first non-empty argument. “Largest” means the larger, if numeric, or lexicographically last, if string.

# Usage: MAX(arg1, arg2, ...)
# Examples
MAX($mysql_latency_ms, $redis_latency_ms)
MAX(1, DIV($total_volume, $count))

LOG10 

Computes the base-10 logarithm of the argument. Strings are parsed into numbers if possible. Unparseable strings, and arguments less than or equal to 0, evaluate to null.

# Usage: LOG10(arg1)
# Examples
LOG10($duration_ms)

BUCKET 

Computes discrete (categorical) bins, or buckets, to transform continuous fields into categorical ones. This can be useful to group data into groups. The syntax is BUCKET( $column, size, [min, [max]]). The function returns size-sized buckets from min to max. For example, BUCKET( $column, 10, 0, 30) will return groups named < 0, 0 - 10, 10 - 20, 20 - 30, and > 30.

If only the min is specified, then the function will run without an upper bound; if neither a min nor max is specified, then the function will run without either bound, starting from a bucket 0 - size.

In all versions, points on the boundary between two bins will fall into the lower bin. The size, min, and max may not be columns. If the column is not a float value, the function returns null.

# Usage: BUCKET( $column, size, [min, [max]])
# Examples
BUCKET($duration_ms, 500, 0, 3000) # size, min and max
BUCKET($current_budget, 10, -5) # min only
BUCKET($num_users, 10) # size only
On this page: