Powered By GitBook
SUM_BY_KEY
Calculate the sum of numeric key values of objects

Description

Calculates the sum of all numeric key values of objects in the given list. Returns 0 if the list is empty or all key values are non-numeric.

Function signature

1
SUM_BY_KEY(objects: Array, keyname: String) => Number
Copied!
Parameter
Description
Objects
List of objects
Key name
Name of the key whose values to sum

Examples

1
products = [{"name":"Duct tape","price":5},{"name":"Swiss army knife","price":60}]
2
animals = [
3
{
4
"name": "dog",
5
"weight": 123
6
},
7
{
8
"name": "cat",
9
"weight": 48
10
},
11
{
12
"name": "rat",
13
"weight": 10
14
}
15
]
Copied!
Formula
Return value
SUM_BY_KEY(products, "price")
65
SUM_BY_KEY(animals, "weight")
181
Last modified 11mo ago
Export as PDF
Copy link