Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.
Dan Gorman edited this page Nov 29, 2018 · 3 revisions

The SUM Function

Function Group: Statistical

SUM returns the sum of one or more numbers.

Syntax

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

  • arg1 is a number
  • arg2 is optional, and follows the same requirements as arg1
  • SUM can take an arbitrary number of optional arguments

Uses

Let's say we're given a response with some vehicle information that looks like this:

{  
   "vehicle_info":{  
      "vin":"16m2flcb1",
      "make":"Ford",
      "model":"T",
      "cylinders":2,
      "horsepower":20,
      "weight_kg":750
   }
}

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 like this:

SUM(vehicle_info.horsepower, vehicle_info.weight_kg)

Which returns 770.

Other examples:

SUM(vehicle_info.horsepower, vehicle_info.horsepower) => 40

SUM(vehicle_info.cylinders) => 2

SUM(1, 2, 3, 4, vehicle_info.horsepower) => 30

Notes

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 nil value cannot be coerced into a number.

Clone this wiki locally