---
schema_version: "1"
id: 4220d6e0d54d895101273027e77ca16f09c7b48422bd1a2c9af962712866e3a0
title: sumBy
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.3/dw-arrays-functions-sumby.md
canonical_url: https://docs.mulesoft.com/dataweave/2.3/dw-arrays-functions-sumby
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 6b4e2ec82bead8373b7cd5fa56d6a3c428cbdd5823ec64b9350c44a0f9f22910
description: MuleSoft Documentation Site
release: "2.3"
latest: false
---
---
product: DataWeave
version: 2.3
---

# sumBy

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

## sumBy(Array<T>, (T) -> Number): Number

Returns the sum of the values of the elements in an array.

### Parameters

<table><colgroup><col> <col></colgroup><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>array</code></p></td><td><p>The input array.</p></td></tr><tr><td><p><code>numberSelector</code></p></td><td><p>A DataWeave selector that selects the values of the numbers in the input array.</p></td></tr></tbody></table>

### Example

This example calculates the sum of the values of elements some arrays. Notice that both of the
`sumBy` function calls produce the same result.

#### Source

```DataWeave
 %dw 2.0
 import * from dw::core::Arrays
 output application/json
 ---
{
  "sumBy" : [
    [ { a: 1 }, { a: 2 }, { a: 3 } ] sumBy $.a,
    sumBy([ { a: 1 }, { a: 2 }, { a: 3 } ], (item) -> item.a)
  ]
}
```

#### Output

```json
{ "sumBy": [6, 6] }
```
