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

# `distinct_count`

## Description

Returns the number of distinct, non-null values for a given expression.

* Each unique value is counted once per group.

Note

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

## Syntax

```
distinct_count(expression: any): number
```

## Arguments

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

## Example

**Use case: Count active users per application**

Suppose you want to know how many unique users have been active in a given timeframe.

### Example data

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

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

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

### Example query

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

### Example output

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