SUM

SUM returns the sum of one or more numbers. It can take an arbitrary number of optional arguments.

Function category: Statistical

For numerical functions (like SUM, AVERAGE, and ROUND), incoming values will be coerced into numbers where possible. If a key in the data source has been deleted (meaning no value is now returned), this will yield an error as a null value cannot be coerced into a number.

Syntax

SUM(arg1, [arg2, ...])

Arguments

Description

arg1

A number.

arg2

Optional. Same requirements as arg1.

Example2

Let's say we're given a response with the following vehicle information:

{
"vehicle_info":{
"vin":"16m2flcb1",
"make":"Ford",
"model":"Mustang GT500",
"cylinders":8,
"horsepower":460,
"weight_kg":1720
}
}

If we want an endpoint with an attribute called horsepower_plus_weight, we're able to access and sum the keys of the JSON object using SUM.

SUM(vehicle_info.horsepower, vehicle_info.weight_kg)

This returns the following:

2180

Example 2: Other combinations

SUM horsepower + horsepower:

SUM(vehicle_info.horsepower, vehicle_info.horsepower)

This results in the following:

920

Number of cylinders:

SUM(vehicle_info.cylinders)

This results in the following:

8

Example 3: Use of additional arguments

In the following example, five values are summed, including four integers and one reference:

SUM(20, 20, 25, 25, vehicle_info.horsepower)

This results in the following:

550