Weighted sum measures a quantity while accounting for how long it applies during a billing cycle. Use it for quantities that change over time, such as allocated storage or memory.
Each event adds to the running quantity at its timestamp. Lago weights each quantity by how long it applies, then divides the total by the billing cycle duration. The result keeps the original unit: storage measured in GB produces an average in GB.
Configure the metric
Setfield_name to the event property you want to measure.
weighted_interval is required and accepts seconds only.
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.
Create the metric
- Dashboard
- API
- Go to Billable metrics in the side menu.
- Create a new billable metric.
- Enter a name, a code and an optional description.
- Select Weighted sum as the aggregation type.
- Choose whether the measured quantity carries over or resets at the end of each billing cycle.
- Select the event property you want to measure.
- Define the
weighted_intervalused for time proration (seconds). - Add filters if you want to group usage by dimensions such as region or provider.
- Click Add billable metric.
Calculation example
This example covers January 1, 2027 at 00:00 UTC through February 1 at 00:00 UTC, a 31-day billing cycle. The opening quantity is 0 GB andrecurring is false.
The first event adds 20 GB on January 16 at 00:00 UTC. The second adds 10 GB on January 17 at 00:00 UTC, bringing the running quantity to 30 GB. No more events occur during the cycle.
Event 1
Event 2
Multiply each running quantity by its duration, add the results, then divide by the full billing cycle duration:
Average storage = (0 × 15 + 20 × 1 + 30 × 15) / 31 ≈ 15.1612903226 GB
The same calculation in seconds is (0 × 1,296,000 + 20 × 86,400 + 30 × 1,296,000) / 2,678,400. The result is a time-weighted average in GB. The displayed decimal is approximate, before any configured rounding.
Aggregation examples
Compare how aggregation types calculate usage.
Rounding
Choose how to round the measured quantity.
Create a billable metric (API)
POST /billable_metricsIngest usage
Send usage events to Lago.