---
schema_version: "1"
id: 5e13d05303c5d0b9e116da1e8dbdbca1b9b3a3a27844251519fbcb435864b26f
title: sumBy
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/dataweave/2.4/dw-arrays-functions-sumby.md
canonical_url: https://docs.mulesoft.com/jp/dataweave/2.4/dw-arrays-functions-sumby
source_site: docs.mulesoft.com
content_type: documentation
content_hash: bd8c6f4d0fcd5cf98b31c2a3f05d9dd3bd3e2da6a69e188f81bda13b243b6ef9
description: MuleSoft Documentation Site
release: "2.4"
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 で導入されました。_​