> For the complete documentation index, see [llms.txt](https://docs.nexthink.com/platform/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.nexthink.com/platform/ja/understanding-key-data-platform-concepts/nexthink-query-language-nql/nql-keywords/nql-compute.md).

# NQL計算

`compute` コマンドはイベントテーブルからメトリクスを集計および抽出し、結果テーブルにオブジェクトごとのメトリクスが含まれた新しい列として追加します。 これは `with` または `include` 句の後にのみ使用できます。

### 構文 <a href="#nqlcompute-syntax" id="nqlcompute-syntax"></a>

{% code overflow="wrap" lineNumbers="true" %}

```
...
| include...
| compute <new_metric> = <metric>.<aggregation function>
```

{% endcode %}

{% code overflow="wrap" lineNumbers="true" %}

```
...
| with...
| compute <new_metric> = <metric>.<aggregation function>
```

{% endcode %}

### 例 <a href="#nqlcompute-example" id="nqlcompute-example"></a>

{% code overflow="wrap" lineNumbers="true" %}

```
デバイス 過去 7d
| 過去 7d の execution.crashes を含める
| nb_crashes = number_of_crashes.sum() を計算する
```

{% endcode %}

### ‘count()’ 関数を使用する <a href="#nqlcompute-usingwiththecount-function" id="nqlcompute-usingwiththecount-function"></a>

フィールドを指定せずに使用すると、`count()` 集計関数がイベントテーブルに適用されます。 例えば、次のクエリでは、`compute` 句によってデバイスごとに起動数の新しい列が追加されます。

{% code overflow="wrap" lineNumbers="true" %}

```
デバイス 過去 7d
| 過去 7d の device_performance.boots を含める
| nb_boots = count() を計算する
```

{% endcode %}

一意のインベントリオブジェクトを新しい列として数えることも、`<object>.count()` 構文を使用して行えます。 関連イベントがあるかどうかに基づいて、1 または 0 を値として新しい列を追加します。 次の例では、コンピュート句は、過去 7 日間に起動されたデバイスには 1 を、起動記録がないデバイスには 0 を返します。 最後の文では、`summarize` 句を使用して起動されたデバイスの比率を計算します。

{% code overflow="wrap" lineNumbers="true" %}

```
デバイス 過去 7d
| 過去 7d の device_performance.boots を含める
| nb_devices_with_boots = device.count() を計算する
| summarize ratio_devices_with_boots = nb_devices_with_boots.sum()/count()
```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.nexthink.com/platform/ja/understanding-key-data-platform-concepts/nexthink-query-language-nql/nql-keywords/nql-compute.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
