distinct
distinct, function
def nosort process distinct(value: boolean): number
def nosort process distinct(value: date ): number
def nosort process distinct(value: number ): number
def nosort process distinct(value: text ): number
def nosort process distinct(value: week ): number
def nosort process distinct(value: month ): number
def nosort process distinct(value: enum ): number
Returns the count of distinct values in a group.
value: values to count per group.
Examples
table T = with
[| as Group, as Value |]
[| "A", 1 |]
[| "A", 1 |]
[| "A", 2 |]
[| "B", 2 |]
[| "B", 3 |]
table G[g] = by T.Group
G.Count = distinct(T.Value)
show table "Distinct" with
g as "Group"
G.Count as "Count"
This produces the following table:
| Group | Count |
|---|---|
| A | 2 |
| B | 2 |
table U = with
[| as W, as M |]
[| week(2024, 1), month(2024, 1) |]
[| week(2024, 2), month(2024, 1) |]
[| week(2024, 1), month(2024, 2) |]
show summary "Distinct periods" with
distinct(U.W) as "Weeks"
distinct(U.M) as "Months"
Recipes and best practices
For large groups, prefer distinctapprox when an
approximation is acceptable. If you only need to know whether all values are
equal, use areSame instead.