Copy as Markdown[Open in ChatGPT](https://chatgpt.com/?q=Read%20https%3A%2F%2Fcoralogix.com%2Fdocs%2Fdataprime%2Flanguage-reference%2Ffunctions-reference%2Faggregation%2Fapprox_count_distinct.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)[Open in Claude](https://claude.ai/new?q=Read%20https%3A%2F%2Fcoralogix.com%2Fdocs%2Fdataprime%2Flanguage-reference%2Ffunctions-reference%2Faggregation%2Fapprox_count_distinct.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)

# `approx_count_distinct`

## Description

Returns an approximate count of unique, non-null values for a given expression.

* A document is counted if it contains a unique, non-null value.
* The result is approximate, optimized for performance rather than precision.

Note

`approx_count_distinct` is an aggregation function and must be used with a grouping keyword such as `groupby`.

## Syntax

```
approx_count_distinct(expression: any): number
```

## Arguments

| Name         | Type  | Required | Description                                                        |
| ------------ | ----- | -------- | ------------------------------------------------------------------ |
| `expression` | `any` | **true** | Expression whose unique, non-null values are counted approximately |

## Example

**Use case: Estimate the number of active users per application**

Suppose you want to know how many unique users have been active in a given timeframe. Since you only care whether the number is above a threshold, an approximate count is sufficient.

### Example data

```
{ "applicationname": "checkout-service", "username": "alice" },

{ "applicationname": "checkout-service", "username": "bob" },

{ "applicationname": "checkout-service", "username": "charlie" },

{ "applicationname": "checkout-service", "username": "alice" }
```

### Example query

```
groupby $l.applicationname aggregate approx_count_distinct($d.username) as active_users
```

### Example output

| applicationname  | active\_users |
| ---------------- | ------------- |
| checkout-service | 3             |
