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 |