# NQL count()

The `count()` function returns the number of unique objects or punctual events.

## Using with the ‘compute’ clause <a href="#nqlcount-usingwiththecomputeclause" id="nqlcount-usingwiththecomputeclause"></a>

### For objects: <a href="#nqlcount-forobjects" id="nqlcount-forobjects"></a>

It returns the number of unique objects.

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

```
devices during past 7d
| include execution.events during past 7d
| compute number_of_devices = device.count()
```

{% endcode %}

### For punctual events: <a href="#nqlcount-forpunctualevents" id="nqlcount-forpunctualevents"></a>

It computes the number of events per object.

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

```
devices during past 7d
| include execution.crashes during past 7d
| compute number_of_crashes_ = count()
```

{% endcode %}

### For sampled events: <a href="#nqlcount-forsampledevents" id="nqlcount-forsampledevents"></a>

It is not recommended to use the `count()` function on sampled events as it will return the number of data samples, not the actual number of events.

## Using with the ‘summarize’ clause <a href="#nqlcount-usingwiththesummarizeclause" id="nqlcount-usingwiththesummarizeclause"></a>

When used with the `summarize` clause, the `count()` function always returns the number of records in the root table.

### For objects: <a href="#nqlcount-forobjects-.1" id="nqlcount-forobjects-.1"></a>

It returns the number of objects.

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

```
devices during past 7d
| summarize c1 = count()
```

{% endcode %}

### For punctual events: <a href="#nqlcount-forpunctualevents-.1" id="nqlcount-forpunctualevents-.1"></a>

It returns the number of events.

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

```
execution.crashes during past 7d
| summarize c1 = number_of_crashes.count()
```

{% endcode %}

Note that the following query returns the number of records of root table (in this case, devices), not the number of unique events. To count events, use the `sum()` function in the `summarize` clause instead.

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

```
devices during past 7d
| include execution.crashes during past 7d
| compute number_of_crashes_ = number_of_crashes.count()
| summarize c1 = number_of_crashes_.count()
```

{% endcode %}

### For sampled events: <a href="#nqlcount-forsampledevents-.1" id="nqlcount-forsampledevents-.1"></a>

It is not recommended to use the `count()` function on sampled events as it will return the number of data samples, not the actual number of events.


---

# Agent Instructions: 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:

```
GET https://docs.nexthink.com/platform/understanding-key-data-platform-concepts/nexthink-query-language-nql/nql-functions/nql-count.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
