# countdistinct()

`countdistinct(col [, ...cols])` counts the number of distinct values of the provided column(s) in the input stream. If multiple columns are provided, their values are treated as a tuple.

## Technical Notes

* If there are at most 1000 distinct values in the input stream, it will return the exact value.
* If there are >1000 distinct values, it will fall back to a variant of the [hyperloglog algorithm](https://en.wikipedia.org/wiki/HyperLogLog) with a precision of 14.
  * For most inputs, this has an average error of 0.5% and a p95 error of 1.5%.

## Returns

A table with one row and one column, called `@q.uniq`.

## Example

Analyze AWS CloudTrail logs to count the number of distinct IAM users making AWS API calls.

```python
@scnr.source_type: "aws:cloudtrail"
and userIdentity.type: "IAMUser"
| countdistinct(userIdentity.arn)
```


---

# 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.scanner.dev/scanner/using-scanner-complete-feature-reference/querying-and-analysis/aggregation-functions/countdistinct.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.
