Sum, Lago adds the calculated values together.
Create a custom expression
Setexpression to the calculation you want Lago to run for each event. Choose an aggregation type based on how you want to combine or select the results. Custom expressions work with every aggregation type except Count.
- Dashboard
- API
- Define the
nameandcodeof the billable metric. - Choose an aggregation type.
- Select Custom expression as the aggregation option instead of Unique field.
- Enter your custom expression in the side panel.
- Test the custom expression.
- Save the billable metric.

Create a custom expression for a billable metric
Worked example
Thestorage metric above receives one event for contract_example:
Sum aggregation adds these 60 GB-hours to the values calculated from other matching events in the billing cycle.
Test a custom expression
Test your expression with a sample event before saving the metric. Use values you can calculate manually, then compare your expected result with Lago’s result. For the storage example above, the expected result is 60. The Dashboard testing tool runs the expression against a sample event whose fields you can edit. If the expression is invalid, Lago returns an error. Fix the expression before saving the metric.- Use the supported attributes:
event.code,event.timestampand properties underevent.properties. - Use precise paths:
event.timestampfor the event timestamp,event.properties.your_fieldfor a property.

Test your custom expression
Supported expressions
Use an expression that matches the value you want to calculate:
The following sections describe the supported attributes, literal values, operators and functions:
If you need an expression Lago does not support yet, contact the Lago team or contribute it to the open-source project.
Event attributes
Lago expressions may include the following event attributes:event.code(event code)event.timestamp(event timestamp)event.properties.[property_name](event property)
event.properties.my_property is a valid event attribute.
Literal values
You can include values directly in an expression:123(integer)123.45(decimal)'Hello, world!'(string)
Operators
Lago expressions may include basic operators:+(addition)-(subtraction)*(multiplication)/(division)- unary minus (
-12)
Functions
CONCAT
CONCAT joins two or more strings.
str1: The first string to concatenatestr2: The second string to concatenatestrs: (Optional) Additional strings to concatenate.
CONCAT(event.properties.user_id, '-', event.properties.app_id)
ROUND
ROUND rounds a number to the specified precision.
value: The number to roundprecision: (Optional) Number of decimal places. Defaults to0.
ROUND(14.2355)returns14ROUND(14.2355, 0)returns14ROUND(14.2355, 2)returns14.24ROUND(14.2355, -1)returns10
FLOOR
FLOOR rounds a number down to the specified precision. With the default precision of 0, it rounds down to an integer.
value: The number to roundprecision: (Optional) Number of decimal places. Defaults to0.
FLOOR(16.2365)returns16FLOOR(16.2365, 0)returns16FLOOR(16.2365, 2)returns16.23FLOOR(16.2365, -1)returns10
CEIL
CEIL rounds a number up to the specified precision. With the default precision of 0, it rounds up to an integer.
value: The number to roundprecision: (Optional) Number of decimal places. Defaults to0.
CEIL(14.2345)returns15CEIL(14.2345, 0)returns15CEIL(14.2345, 2)returns14.24CEIL(14.2345, -1)returns20
LEAST
LEAST returns the smallest of two or more numbers.
num1: The first number to comparenum2: The second number to comparenums: (Optional) Additional numbers to compare.
LEAST(event.properties.disk1_usage_mb, event.properties.disk2_usage_mb, 10.0)
GREATEST
GREATEST returns the largest of two or more numbers.
num1: The first number to comparenum2: The second number to comparenums: (Optional) Additional numbers to compare.
GREATEST(event.properties.memory_mb, 10.0)
Aggregation types
What happens to the computed values.
Ingest usage
Send the properties your expression reads.
Create a billable metric (API)
POST /billable_metricsBillable metric object (API)
The
expression field.