The unique count aggregation type counts only the unique values of a specified event property.
UNIQUE COUNT calculation method
UNIQUE COUNT billable metric
Here is how you can create a unique count aggregation from the UI:
- Access the “Billable metrics” section via the side menu;
- Create a new billable metric;
- Define a name, a code and an optional description;
- Select “count unique” as the aggregation type;
- Define it this metric is
metered
or recurring
;
- Define the property to aggregate;
- Apply dimension groups if any; and
- Click “Add billable metric”.
This billable metric can be both metered
or recurring
.
Here is how you can create a unique count aggregation from the UI:
- Access the “Billable metrics” section via the side menu;
- Create a new billable metric;
- Define a name, a code and an optional description;
- Select “count unique” as the aggregation type;
- Define it this metric is
metered
or recurring
;
- Define the property to aggregate;
- Apply dimension groups if any; and
- Click “Add billable metric”.
This billable metric can be both metered
or recurring
.
LAGO_URL="https://api.getlago.com"
API_KEY="__YOUR_API_KEY__"
curl --location --request POST "$LAGO_URL/api/v1/billable_metrics" \
--header "Authorization: Bearer $API_KEY" \
--header 'Content-Type: application/json' \
--data-raw '{
"billable_metric": {
"name": "API Request",
"code": "api_requests",
"description": "Number of API requests.",
"aggregation_type": "unique_count_agg",
"field_name": "request_id",
"group": {}
}
}'
Calculation example
Lago calculates the COUNT_DISTINCT(events.properties.property_name)
for the two following events received.
//Event received #1
{
"transaction_id": "transaction_1",
"external_customer_id": "1",
"timestamp": "2022-03-16T00:00:00Z",
"code": "api_requests",
"properties": {
"request_id": "id_1"
}
}
//Event received #2
{
"transaction_id": "transaction_2",
"external_customer_id": "1",
"timestamp": "2022-03-17T00:00:00Z",
"code": "api_requests",
"properties": {
"request_id": "id_1"
}
}
In that case, with this aggregation type, Lago only counts the unique values request_id
property in the event payloads, resulting in a billable value of 1 unit.
Responses are generated using AI and may contain mistakes.