Skip to main content
Count unique measures how many distinct values appear in an event property. Use it to track unique users, seats or request identifiers. Repeated events with the same value count once.
Diagram of the Count unique aggregation, counting the unique values of a property

Count unique calculation method

Configure the metric

Set field_name to the event property you want to measure. Choose what happens when a billing cycle ends:
  • recurring: true: Lago keeps the quantity and carries it into the next cycle.
  • recurring: false: Lago resets the quantity, so each cycle starts fresh.
See Metric recurrence.

Create the metric

  1. Go to Billable metrics in the side menu.
  2. Create a new billable metric.
  3. Enter a name, a code and an optional description.
  4. Select Count unique as the aggregation type.
  5. Choose whether the measured quantity carries over or resets at the end of each billing cycle.
  6. Select the event property you want to measure.
  7. Add filters if you want to group usage by dimensions such as region or provider.
  8. Click Add billable metric.

Calculation example

The two example events below belong to contract_example and the same billing cycle. Their timestamps are January 16 and 17, 2027 at 00:00 UTC.
Event 1
Event 2
Both events contain request_id: "id_1". Lago counts that value once, so the measured quantity is 1.

Add or remove unique values

Events sent to a Count unique metric accept an operation_type property that controls whether the value is added to or removed from the count:
  • add: adds the unique value. Optional. Lago adds by default when operation_type is omitted.
  • remove: removes the unique value from the count. Required whenever you want to remove a unit.
Event removing a previously counted unique value

Aggregation examples

Compare how aggregation types calculate usage.

Metered products

Connect your metric to a Product.

Create a billable metric (API)

POST /billable_metrics

Ingest usage

Send usage events to Lago.