Skip to content

abs

Description

Returns the absolute value of a number. Useful for computing the total difference between two values without regard to sign.

Syntax

Like many functions in DataPrime, abs supports two notations, function and method notation. These interchangeable forms allow flexibility in how you structure expressions.

abs(number: number): number
(number: number).abs(): number

Arguments

NameTypeRequiredDescription
numbernumbertrueThe value to convert to a positive number

Example

Use case: Calculate the difference between two timestamps Generate a time_difference field based on two timestamp values. Using abs avoids worrying about which timestamp is greater.

{
    "first_timestamp": 1728636298,
    "second_timestamp": 1728636358
}
source logs | create time_difference from abs(first_timestamp - second_timestamp)
source logs | create time_difference from (first_timestamp - second_timestamp).abs()

Output

{
    "first_timestamp": 1728636298,
    "second_timestamp": 1728636358,
    "time_difference": 60
}