Skip to content

distinct_count - Count unique values

The distinct_count function will count a given document if:

  • The document contains a unique, non-null value for a specified field.

NOTE: distinct_count is an aggregation function, so should be used in conjunction with a grouping keyword, like groupby.

Syntax

distinct_count(expression: any)

Arguments

Name Type Required Description
expression any true The non-null value to be counted distinctly

Example - Counting active users

In this example, we wish to understand how many active users there have been in a given timeframe. We can provide the username field to produce a count of the unique users.

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