Skip to main content
The weighted sum aggregation type adds up the value of a defined event property and prorates it based on time used per period. It is useful for automated GB/second calculations.
Prorating is available per second per period. Contact the Lago team if you need other proration options, such as hourly rates.
Diagram of the WEIGHTED SUM aggregation, summing a property prorated over the time it was used

WEIGHTED SUM calculation method

WEIGHTED SUM billable metric

Here is how you can create a weighted sum aggregation from the UI:
  1. Access the “Billable metrics” section via the side menu;
  2. Create a new billable metric;
  3. Define a name, a code and an optional description;
  4. Select “weighted sum” as the aggregation type;
  5. Define if this metric is metered or recurring;
  6. Define the property to aggregate;
  7. Define the weighted_interval used for time proration (Lago currently supports seconds only);
  8. Apply filters if any; and
  9. Click “Add billable metric”.
This billable metric can be either metered or recurring.

Calculation example

Lago calculates the SUM(events.properties.property_name) / (DATEDIFF(SECOND, timestamp.event_1, timestamp.event_2) + 1) * (DATEDIFF(SECOND, 'period_start', 'period_end') + 1) for the two following events received.
In that case, with this aggregation type, Lago adds up the values of the gb property in the event payloads, but prorates it based on time used during the current period. Keep in mind that the entire month comprises 2,678,400 seconds. The first 20 GB has been used for a day (86,400 seconds), and the 30 GB (20 + 10) has been used for 15 days (1,296,000 seconds till the end of the month):
  • (20 / 2678400) x 86400 = 0.64516129032 GB/s
  • (30 / 2678400) x 1296000 = 14.5161290323 GB/s
  • 0.64516129032 + 14.5161290323 = 15.1612903226 GB/s