Berserk Docs
Scalar Functions

Introduction to Scalar Functions

Scalar function overview and categories

Scalar functions take one or more values and return a single value. Use them in project, extend, and where expressions to transform or compute values per row:

logs
| extend hour = hourofday(timestamp), msg = tolower(body)
| where strlen(msg) > 100

For a full introduction to writing queries, see Writing Queries.

String Functions

FunctionDescription
containsIndicate whether a string contains another string (case-insensitive).
contains_csIndicate whether a string contains another string (case-sensitive).
countofCounts occurrences of a substring in a string.
endswithIndicate whether a string ends with another string (case-insensitive).
endswith_csIndicate whether a string ends with another string (case-sensitive).
extractExtracts a match for a regular expression from a string.
extract_allExtracts all matches for a regular expression from a string.
format_bytesFormats a size in bytes as text, such as 19.08 MB.
hasIndicate whether a string contains a whole term (case-insensitive).
has_any_indexReturns the index in the lookup array of the first element found as a term in the source string, or -1.
has_any_ipv4Indicate whether a text contains any of several IPv4 addresses, matched as in has_ipv4.
has_any_ipv4_prefixIndicate whether a text contains an IPv4 address beginning with any of several prefixes, matched as in has_ipv4_prefix.
has_csIndicate whether a string contains a whole term (case-sensitive).
has_ipv4Indicate whether a text contains an IPv4 address.
has_ipv4_prefixIndicate whether a text contains an IPv4 address that begins with a prefix.
hasprefixIndicate whether a string starts with a word prefix (case-insensitive, word boundary matching).
hasprefix_csIndicate whether a string starts with a word prefix (case-sensitive, word boundary matching).
hassuffixIndicate whether a string ends with a word suffix (case-insensitive, word boundary matching).
hassuffix_csIndicate whether a string ends with a word suffix (case-sensitive, word boundary matching).
indexofReturns the zero-based index of the first occurrence of a substring.
indexof_regexReturns the zero-based character position of a regular expression's first match, or of its n-th non-overlapping match, or -1 when there is none.
isasciiWhether every character of the string is ASCII (below U+0080).
isutf8Whether the string is valid UTF-8.
matches regexReturns true if the string matches the regular expression pattern.
parse_command_lineTokenize a command-line string into a dynamic array of arguments.
parse_urlParses a URL string and returns a dynamic object with URL components.
parse_urlqueryParses a URL query string and returns a dynamic object.
parse_versionConverts a version string to a comparable decimal number.
punycode_from_stringEncode a Unicode string into Punycode (the ACE form defined in RFC 3492).
punycode_to_stringDecode a Punycode (RFC 3492 ACE) string back to its Unicode form.
regex_quoteEscapes the regular expression metacharacters .*[]{}()|^$\?+-# with a backslash, so the result matches the input literally.
replace_regexReplaces all regex matches with another string.
replace_stringReplaces all occurrences of a string with another string.
replace_stringsReplaces multiple string pairs in the source.
reverseReverses the input string.
splitSplits a string by a delimiter and returns an array.
startswithIndicate whether a string starts with another string (case-insensitive).
startswith_csIndicate whether a string starts with another string (case-sensitive).
strcatConcatenates between 1 and 64 arguments.
strcat_arrayConcatenates array elements into a string using the specified delimiter.
strcat_delimConcatenates strings with a delimiter.
strcmpCompares two strings and returns -1, 0, or 1.
string_sizeReturns the size of the input string in UTF-8 bytes.
strlenReturns the length of the input string in characters.
strrepRepeats a string a specified number of times.
substringExtracts a substring from the source string starting at the specified position.
tolowerConverts a string to lower case.
toupperConverts a string to upper case.
translateReplaces characters in a string based on character mapping.
trimRemoves leading and trailing match of the specified regex from the source string.
trim_endRemoves trailing match of the specified regex from the source string.
trim_startRemoves leading match of the specified regex from the source string.
unicode_codepoints_from_stringReturns the Unicode code points of a string's characters as a dynamic array.
unicode_codepoints_to_stringBuilds a string from Unicode code points, given as up to 64 int or long arguments, dynamic arrays of them, or a mix.
url_decodeURL-decodes a string.
url_encodeURL-encodes a string.
url_encode_componentPercent-encodes a string for use as one URL component.

Date & Time Functions

FunctionDescription
agoSubtracts the given timespan from the current query timestamp.
datetime_addAdds a specified amount to a datetime value.
datetime_diffReturns the difference between two datetime values.
datetime_list_timezonesReturns the IANA time zone names that datetime_utc_to_local and datetime_local_to_utc accept, as an alphabetically sorted dynamic array.
datetime_local_to_utcConverts a local datetime to UTC.
datetime_partExtracts the specified part from a datetime value.
datetime_utc_to_localConverts a UTC datetime to local time.
dayofmonthExtracts the day of month (1-31) from a datetime value.
dayofweekReturns the timespan since the preceding Sunday.
dayofyearExtracts the day of year (1-366) from a datetime value.
endofdayReturns the end of the day for the given datetime.
endofmonthReturns the end of the month for the given datetime.
endofweekReturns the end of the week for the given datetime.
endofyearReturns the end of the year for the given datetime.
format_datetimeFormats a datetime value as a string.
format_timespanFormats a timespan value as a string.
getyearExtracts the year from a datetime value.
hourofdayExtracts the hour (0-23) from a datetime value.
ingestion_timeReturn the ingestion timestamp of the current row, as recorded by the nursery in the synthetic ingest_time column.
make_datetimeCreates a datetime value from components.
make_timespanCreates a timespan value from components.
monthofyearExtracts the month (1-12) from a datetime value.
nowReturns the current query timestamp as a datetime value.
startofdayReturns the start of the day for the given datetime.
startofmonthReturns the start of the month for the given datetime.
startofweekReturns the start of the week for the given datetime.
startofyearReturns the start of the year for the given datetime.
todatetimeConvert the input to a datetime.
totimespanConvert the input to a timespan.
unixtime_microseconds_todatetimeConverts Unix time in microseconds to a datetime value.
unixtime_milliseconds_todatetimeConverts Unix time in milliseconds to a datetime value.
unixtime_nanoseconds_todatetimeConverts Unix time in nanoseconds to a datetime value.
unixtime_seconds_todatetimeConverts Unix time in seconds to a datetime value.
week_of_yearReturns the ISO 8601 week number (1-53) of a datetime.
weekofyearExtracts the ISO week number (1-53) from a datetime value.

Dynamic / JSON Functions

FunctionDescription
array_concatConcatenate dynamic arrays into a single dynamic array.
array_iffElement-wise select between two values based on a boolean-array condition.
array_index_ofReturn the zero-based index of the first occurrence of lookup in array, optionally starting at start_index.
array_lengthReturn the number of elements in an array.
array_reverseReturn a dynamic array with the elements in reverse order.
array_rotate_leftRotate a dynamic array by count positions to the left.
array_rotate_rightRotate a dynamic array by count positions to the right.
array_shift_leftShift the elements of a dynamic array by count positions to the left.
array_shift_rightShift the elements of a dynamic array by count positions to the right.
array_sliceReturn a contiguous subrange of array between inclusive start and inclusive end indices.
array_sort_ascSort a dynamic array in ascending order.
array_sort_descSort a dynamic array in descending order.
array_splitSplit a dynamic array at one or more indices.
array_sumSum the numeric elements of a dynamic array and return a real.
bag_has_keyReturn true if the property bag contains the given key.
bag_keysReturns an array of all the keys in a property bag (dynamic object).
bag_mergeMerge property bags into a single bag using first-wins collision resolution.
bag_packCreate a property bag (dynamic object) from key-value pairs.
bag_pack_columnsCreate a dynamic property bag whose keys are column names and whose values are the corresponding column values for the current row.
bag_remove_keysRemove specified keys from a property bag.
bag_set_keyReturn the property bag with the given key set to value, inserting or overwriting.
bag_zipBuilds a property bag by pairing an array of keys with an array of values.
column_ifexistsIf a column named column_name exists in the current row set, return its value for the current row; otherwise evaluate and return default.
dynamic_to_jsonSerializes a dynamic value to a canonical JSON string: compact (no whitespace), with property-bag keys sorted at every depth and array order kept.
extract_dynamicExtract a value from a dynamic value using a JSONPath expression.
extract_jsonExtract a value from a JSON string using a JSONPath expression.
jaccard_indexReturn the Jaccard similarity |A ∩ B| / |A ∪ B| of two dynamic arrays treated as sets.
minhashReturns a MinHash signature of a set: a dynamic array of k longs whose positions agree between two sets with probability equal to their Jaccard similarity.
minhash_bandsSplits a MinHash signature into bands of rows_per_band positions and returns one key per band, as a dynamic array of longs, for LSH bucketing with mv-expand and summarize by.
minhash_similarityReturns the fraction of positions at which two MinHash signatures agree: an estimate of the Jaccard similarity of the sets they came from.
pack_allCreate a property bag containing all column values.
pack_arrayBuild a dynamic array from the given arguments, in order.
parse_jsonParse a JSON string into a dynamic value.
parse_xmlParse an XML string into a dynamic value.
rangeGenerates a dynamic array of equally spaced values: start, start + step, … up to and including stop, at most 1048576 of them.
repeatBuild a dynamic array by repeating value count times.
set_differenceReturn the distinct elements of the first dynamic array that are not present in any of the remaining arrays, preserving first-seen order.
set_has_elementReturn true if value exists in the dynamic array.
set_intersectReturn the distinct elements that appear in every dynamic array argument, preserving first-seen order from the first array.
set_unionReturn the distinct elements from all dynamic-array arguments, preserving first-seen order.
similar_bandsEmbeds text with the semantic-search model, takes the sign of each coordinate of the embedding after a fixed random rotation (a SimHash), and returns one key per band of rows_per_band sign bits, as a dynamic array of bands longs, for LSH bucketing with mv-expand and summarize by.
summarize_graphCollapse a canonical {nodes, edges} graph (from make_graph) by a node attribute.
treepathEnumerate the JSON paths (in bracket notation) reachable inside a dynamic value.
zipZip two or more dynamic arrays element-wise.

Math Functions

FunctionDescription
absReturns the absolute value of a numeric or timespan expression.
acosReturns the arc cosine of the input (in radians).
aroundWhether a value lies within a distance of a center, inclusive: abs(value - center) <= delta.
asinReturns the arc sine of the input (in radians).
atanReturns the arc tangent of the input (in radians).
atan2Returns the angle (in radians) between the positive x-axis and the point (x, y).
beta_cdfRegularised incomplete-beta CDF of Beta(α, β) at x.
beta_invInverse CDF (quantile) of Beta(α, β) at probability p.
beta_pdfProbability density of Beta(α, β) at x.
binRound values down to a bin of a given bin size.
bin_atRound values down to a bin of a given size relative to a fixpoint.
bin_autoAutomatically bins datetime values into human-friendly intervals based on the query time range.
binary_andReturn the bitwise AND of two 64-bit integers.
binary_notReturn the bitwise negation of a 64-bit integer: every bit is flipped, so binary_not(x) equals -x - 1.
binary_orReturn the bitwise OR of two 64-bit integers.
binary_shift_leftShift a 64-bit integer left by a number of bits.
binary_shift_rightShift a 64-bit integer right by a number of bits.
binary_xorReturn the bitwise exclusive OR of two 64-bit integers.
bitset_count_onesReturn the number of set bits in the two's-complement representation of an integer.
ceilingCalculates the smallest integer greater than, or equal to, the specified numeric expression.
cosReturns the cosine of the input angle in radians.
cotReturns the cotangent of the input angle in radians.
degreesConverts radians to degrees.
erfError function erf(x) = (2/√π) ∫₀ˣ e^{-t²} dt.
erfcComplementary error function erfc(x) = 1 - erf(x).
expReturns e raised to the power of the numeric expression.
exp10Returns 10 raised to the power of the numeric expression.
exp2Returns 2 raised to the power of the numeric expression.
floorRounds values down to a fixed-size bin.
gammaGamma function Γ(x).
isfiniteReturns whether the input is a finite value (not infinity and not NaN).
isinfReturns whether the input is an infinite value (positive or negative infinity).
isnanReturns whether the input is NaN (Not a Number).
logReturns the natural logarithm of the numeric expression.
log10Returns the base-10 logarithm of the numeric expression.
log2Returns the base-2 logarithm of the numeric expression.
loggammaNatural log of the absolute value of the gamma function, equivalent to lgamma(x) in C99.
max_ofReturn the maximum of 2 to 64 comparable arguments.
min_ofReturn the minimum of 2 to 64 comparable arguments.
notReturn the logical negation of a boolean: true becomes false, false becomes true, and null stays null.
piReturns the constant value of Pi.
powReturns the value raised to the specified power.
radiansConverts degrees to radians.
randReturn a pseudo-random real.
roundReturns the rounded number to the specified precision.
signReturns the sign of a numeric expression as a real (-1.0, 0.0 or 1.0).
sinReturns the sine of the input angle in radians.
sqrtReturns the square root of the numeric expression.
tanReturns the tangent of the input angle in radians.
welch_testTwo-tailed p-value for the Welch unequal-variances t-test given the mean, variance, and count of each of two samples.

Type Functions

FunctionDescription
asboolExtract a boolean from a dynamic or pass through a bool value.
asdatetimeExtract a datetime from a dynamic or pass through a datetime value.
asdoubleExtract a real from a dynamic or pass through an int/long/real value.
asintExtract a 32-bit integer from a dynamic or pass through an int/long value.
aslongExtract a 64-bit integer from a dynamic or pass through an int/long value.
asnumericExtract numeric value from dynamic or pass through numeric types.
asstringExtract a string from a dynamic or pass through a string value.
astimespanExtract a timespan from a dynamic or pass through a timespan value.
estimate_data_sizeEstimates the data size in bytes for the specified columns.
gettypeReturn the type of a value as a string, from ADX's closed set of names.
isemptyReturns true if the argument is an empty string or is null.
isnotemptyReturns true if the argument is not an empty string and is not null.
isnotnullReturns true if the value is not null.
isnullReturns true if the value is null.
isoteltypeReturns true for rows of the given OpenTelemetry signal type - "span", "log" or "metric".
new_guidReturns a random GUID string.
toboolConvert the input to a boolean.
todoubleConvert the input to a floating point number.
toguidValidates and normalizes a string as a GUID.
tohexConverts a number to a hexadecimal string.
tointConvert the input to a 32-bit integer.
tolongConvert the input to a 64-bit integer.
tostringConvert the input to a string.

IP Address Functions

FunctionDescription
format_ipv4Formats an IPv4 address as dotted text, keeping the leading bits of the smaller of its own /mask and the optional prefix.
format_ipv4_maskFormats an IPv4 address as a CIDR, a.b.c.d/N, keeping the leading bits of the smaller of its own /mask and the optional prefix.
ipv4_compareCompare two IPv4 addresses, returning -1, 0 or 1.
ipv4_is_in_any_rangeWhether an IPv4 address lies in any of several ranges, each matched as in ipv4_is_in_range.
ipv4_is_in_rangeWhether an IPv4 address lies in a range written in IP-prefix notation.
ipv4_is_matchWhether two IPv4 addresses are equal once both are cut to the smallest of their own /masks and the optional prefix (0-32; any other prefix counts as 32).
ipv4_is_privateWhether an IPv4 address is in a private network: 10.0.0.0/8, 172.16.0.0/12 or 192.168.0.0/16.
ipv4_netmask_suffixThe /mask of an IPv4 address, as a long: 32 when it has none, and 32 when the mask is larger than 32.
ipv4_range_to_cidr_listThe fewest CIDR ranges that together cover exactly the IPv4 addresses from start to end, inclusive, as a dynamic array of a.b.c.d/N strings.
ipv6_compareCompare two IPv6 or IPv4 addresses, returning -1, 0 or 1, after cutting both to the smallest of their own /masks and the optional prefix (0-128).
ipv6_is_in_any_rangeWhether an IPv6 or IPv4 address lies in any of several ranges, each matched as in ipv6_is_in_range.
ipv6_is_in_rangeWhether an IPv6 or IPv4 address lies in a range written in IP-prefix notation; an address with its own /mask must have its whole network in the range.
ipv6_is_matchWhether two IPv6 or IPv4 addresses are equal once both are cut to the smallest of their own /masks and the optional prefix (0-128), as in ipv6_compare.
parse_ipv4Converts an IPv4 string to a long number.
parse_ipv4_maskConverts an IPv4 address and prefix to a long, keeping the leading bits of the smaller of its own /mask and the prefix.
parse_ipv6Converts an IPv6 or IPv4 address, optionally with a /mask, to the canonical uncompressed IPv6 string.
parse_ipv6_maskConverts an IPv6 or IPv4 address and prefix to the canonical IPv6 string, keeping the leading bits of the smaller of its own /mask and the prefix.

Encoding Functions

FunctionDescription
base64_decode_toarrayDecodes a base64 string to an array of long values.
base64_decode_toguidDecodes a base64 string to a GUID.
base64_decode_tostringDecodes a base64 string.
base64_encode_fromarrayEncodes an array of bytes (longs from 0 to 255) as a base64 string.
base64_encode_fromguidEncodes a GUID to base64.
base64_encode_tostringEncodes a string to base64.
gzip_compress_to_base64_stringCompresses a string's UTF-8 bytes into a gzip stream (deflate level 6) and encodes it as base64.
gzip_decompress_from_base64_stringDecodes a base64 string and decompresses the gzip stream in it, which must end with a matching CRC-32 and size.
zlib_compress_to_base64_stringCompresses a string's UTF-8 bytes into a zlib stream (deflate level 6) and encodes it as base64.
zlib_decompress_from_base64_stringDecodes a base64 string and decompresses the zlib stream in it.

Hash Functions

FunctionDescription
hashReturns a hash value for the input value.
hash_combineCombines hash values of two or more hashes into a single hash value.
hash_manyReturns a combined hash value of multiple values.
hash_md5Returns the MD5 hash value of the input, encoded as a hex string.
hash_sha1Returns the SHA-1 hash value of the input, encoded as a hex string.
hash_sha256Returns the SHA-256 hash value of the input, encoded as a hex string.
hash_xxhash64Returns an xxhash64 value for the input value.

Series Functions

FunctionDescription
series_absCalculates the absolute value of each element in a numeric series.
series_acosApply acos element-wise to a numeric dynamic series.
series_addElement-wise addition of two numeric series.
series_asinApply asin element-wise to a numeric dynamic series.
series_atanApply atan element-wise to a numeric dynamic series.
series_avgReturns the average (mean) of all elements in a numeric series, ignoring null values.
series_ceilingRounds each element up to the nearest integer.
series_cosApply cos element-wise to a numeric dynamic series.
series_cosine_similarityCosine similarity (a·b)/(|a|·|b|) of two equal-length numeric series.
series_decomposeDecompose a numeric time series into baseline, seasonal, trend, and residual components.
series_decompose_anomaliesDetects anomalies in a time series using decomposition and outlier detection.
series_decompose_forecastExtend a numeric time series forward by points samples by decomposing into trend + seasonal components and extrapolating both.
series_divideElement-wise division of two numeric series.
series_dot_productDot product Σ aᵢ·bᵢ of two equal-length numeric series.
series_equalsElement-wise equality comparison of two series.
series_expCalculates the exponential (e^x) of each element.
series_fftThe discrete Fourier transform of a series, as two series: the real parts and the imaginary parts.
series_fill_backwardFills missing values in a series by propagating the next valid value backward.
series_fill_constFills missing values in a series with a constant value.
series_fill_forwardFills missing values in a series by propagating the previous valid value forward.
series_fill_linearFills missing values in a series using linear interpolation.
series_firApplies a Finite Impulse Response (FIR) filter to a series.
series_fit_2linesFit two lines (piecewise linear) to the series.
series_fit_2lines_dynamicPiecewise-linear best fit of a numeric series with change-point search.
series_fit_lineFit a line to the series using linear regression.
series_fit_line_dynamicClosed-form ordinary-least-squares fit of a numeric series, returned as a property bag shaped like Microsoft Kusto's output: { slope, interception, rsquare, variance, rvariance, line_fit: [...] }.
series_fit_polyApplies polynomial regression to a series, fitting a curve of the specified degree.
series_floorRounds each element down to the nearest integer.
series_greaterElement-wise greater-than comparison of two series.
series_greater_equalsElement-wise greater-than-or-equal comparison of two series.
series_ifftThe inverse discrete Fourier transform, scaled by 1/n, as two series: the real parts and the imaginary parts.
series_iirApplies an Infinite Impulse Response (IIR) filter to a series.
series_lessElement-wise less-than comparison of two series.
series_less_equalsElement-wise less-than-or-equal comparison of two series.
series_logCalculates the natural logarithm of each element.
series_magnitudeEuclidean L2 norm of a numeric series - sqrt of the sum of squares.
series_maxReturns the maximum value in a numeric series, ignoring null values.
series_minReturns the minimum value in a numeric series, ignoring null values.
series_multiplyElement-wise multiplication of two numeric series.
series_not_equalsElement-wise inequality comparison of two series.
series_outliersDetects outliers in a series using the Tukey fence method.
series_pearson_correlationCalculate the Pearson correlation coefficient between two series.
series_periods_detectDetects periodic patterns in a time series using FFT-based spectral analysis.
series_periods_validateValidates expected periods in a time series using FFT spectral analysis.
series_powElement-wise power operation (base^exponent) of two numeric series.
series_productProduct of all elements in the series (real).
series_seasonalCalculates the seasonal component of a series using median of values at same phase.
series_signReturns the sign of each element (-1 for negative, 0 for zero, 1 for positive).
series_sinApply sin element-wise to a numeric dynamic series.
series_statsComputes statistics (min, max, avg, stdev, variance) for a numeric series.
series_stats_dynamicComputes statistics for a numeric series and returns as a property bag.
series_stdevReturns the population standard deviation of all elements in a numeric series, ignoring null values.
series_subtractElement-wise subtraction of two numeric series.
series_sumReturns the sum of all elements in a numeric series, ignoring null values.
series_tanApply tan element-wise to a numeric dynamic series.

Conditional Functions

FunctionDescription
caseEvaluates predicates in order and returns the first matching value.
coalesceReturns the first non-empty value (not null and not empty string).
iffEvaluates the predicate and returns value_if_true or value_if_false.

Logging Functions

FunctionDescription
extract_log_templateNormalizes a string into a structural template by replacing variable tokens (numbers, UUIDs, IPs, hex values, quoted strings) with typed placeholders.
log_template_hashComputes a hash of the structural log template, for grouping similar logs without allocating the template string.
log_template_idReturns a stable 16-character hex string identifying the structural log template of the input line.
log_template_matchesReturns true when a value has the same structural log template as a sample line: log_template_hash(tostring(field)) == log_template_hash(sample).

Other Functions

FunctionDescription
current_tableReturns the table name for the current row.
dcount_hllCalculate the distinct count from an HLL representation.
nextReturns the value of a column from a row at a given offset after the current row in a serialized row set.
otel_histogram_percentileExtract a percentile from a merged OpenTelemetry histogram (output of otel_histogram_merge).
percentile_array_tdigestExtract a dynamic array of percentiles from a sketch aggregate produced by tdigest().
percentile_tdigestCalculate the percentile from a t-digest representation.
percentrank_tdigestReturn the approximate percentile rank of value in a t-digest / DDSketch sketch produced by the tdigest() aggregate.
prevReturns the value of a column from a row at a given offset before the current row in a serialized row set.
rank_tdigestReturn the approximate count of items ≤ value in a t-digest / DDSketch sketch produced by the tdigest() aggregate.
row_cumsumCalculates the cumulative sum of a column in a serialized row set.
row_numberReturns the current row number in the serialized row set.
row_rank_denseReturns the dense rank of a column in a serialized row set: the rank starts at 1 and increments by 1 each time the column value changes, with no gaps.
row_rank_minReturns the minimum rank of a column in a serialized row set: each row in a run of equal column values gets the 1-based position of the first row in that run, so ranks jump by the run length.
row_window_sessionAssigns a session window to each row of a serialized row set based on a datetime column.

On this page