---
schema_version: "1"
id: e0ad927aa27e8e098f53d4e316235cb497d85db60b8551d09baaa35d61615fe2
title: sumBy
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/dataweave/2.7/dw-arrays-functions-sumby.md
canonical_url: https://docs.mulesoft.com/jp/dataweave/2.7/dw-arrays-functions-sumby
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 4574610527fd194927e82ded4fdd486304cae842f34ebd4d54708f1d9c6b3fda
description: MuleSoft Documentation Site
release: "2.7"
latest: false
---
# sumBy

## [](#sumby1)sumBy<T>(array: Array<T>, numberSelector: (T) -> Number): Number

配列内の要素の値の合計を返します。

### [](#パラメーター)パラメーター

<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 25%;">
<col style="width: 75%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">名前</th>
<th class="tableblock halign-left valign-top">説明</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>array</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">入力配列。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>numberSelector</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">入力配列内で数値の値を選択する DataWeave セレクター。</p></td>
</tr>
</tbody>
</table>

### [](#例)例

次の例では、いくつかの配列で要素の値の合計を計算します。両方の ​`sumBy`​ 関数コールで同じ結果が算出されています。

#### [](#ソース)ソース

```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)
  ]
}
```

#### [](#出力)出力

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

## [](#sumby2)sumBy(array: Null, numberSelector: (Nothing) -> Any): Null

`sumBy`​ を ​`null`​ 値に使用できるようにするヘルパー関数。

_DataWeave バージョン 2.4.0 で導入されました。_