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
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
Example output
| applicationname | active_users |
|---|---|
| checkout-service | 2 |
Theme
Light