The values of Meter Derived Fields are not raw usage data values but always the result of a calculation, which can reference Meter Data Fields, Custom Fields, or Timestamp Fields as source fields. Derived Fields add a very powerful extra dimension of flexibility for setting up the data on which your usage-based pricing plans will be based. This topic explains the different types of field you can reference in Derived Field calculations, how to format those references in calculations, and offers some Derived Field examples:Documentation Index
Fetch the complete documentation index at: https://docs.m3ter.com/llms.txt
Use this file to discover all available pages before exploring further.
Referencing Fields in Derived Field Calculations
Derived Field calculations will typically reference Meter Data Fields. But you’re not restricted to referencing only Meter Data Fields in your calculations. You can also reference Custom Fields and Timestamp Fields, which greatly extends the scope of measures you can derive and subsequently use as the basis for the Aggregations you need to price your Product Plans.Referencing Data Fields
The values of Data Fields in the measurement are available as variables, and can be referenced by the Data Field code, for example:myDataField
Referencing Custom Fields
You can define Custom Fields for your Organization and for the following entity types:- Product
- Plan Template
- Plan
- Meter
- Account
- Account Plan
- Aggregation
- Compound Aggregation
- Contract
- When you reference the Custom Field in a calculation, the value defined for the Custom Field at the Organizational level will be used unless you’ve also defined a Custom Field at the individual entity level.
- If a Custom Field has also been defined at the individual entity level, this value will be used. This allows you to set up default Custom Field values to use for each entity type in your Organization.
Example - Custom Fields for Accounts
For example, suppose you have five Accounts in your Organization: Acct1, Acct2, Acct3, Acct4, and Acct5. You expect to use a Derived Field Calculation that will reference a Custom Field for Accounts to add a weighting to each Account for usage data:- You create a Custom Field for Accounts at the Organization level called
cfAccountand set its value = 25. - You create a Custom Field for Acct2 called
cfAccountand set its value = 20. - You create a Custom Field for Acct4 called
cfAccountand set its value = 30. - You do not create any Custom Fields for Acct1, Acct3, or Acct5.
account.cfAccount
- Acct1 = 25
- Acct2 = 20
- Acct3 = 25
- Acct4 = 30
- Acct5 = 25
Format for Referencing Custom Fields
Here’s the general format to use when referencing Custom Fields:organization.<fieldName>meter.<fieldName>product.<fieldName>account.<fieldName>accountPlan.<fieldName>plan.<fieldName>planTemplate.<fieldName>
Referencing Timestamp Fields
You can reference system variable Timestamp Fields in your Derived Field calculations. All timestamps are numeric values representing the appropriate date/times in Epoch milliseconds:tsts.startOfMonthts.endOfMonthts.startOfMonthUTCts.endOfMonthUTC
etsets.startOfMonthets.endOfMonthets.startOfMonthUTCets.endOfMonthUTC
Derived Field Examples
Please run through the first example as a starter, which shows both the Console setup for the field and the JSON body schema to create the field using a Create Meter API call. Other examples simply give the calculation for the Derived Field:- Example 1 - Gigabytes/second measure
- Example 2 - Convert GB to MB measure
- Example 3 - Convert GB and KB to MB measure
- Example 4 - MB-mins measure
- Example 5 - String Derived Field operations
- Example 6 - Derived Fields for Product Add-Ons
- Example 7 - Derived Field for Seat-Based Pricing
- Links you out to a topic on supported syntax and functions for your Derived Field calculations.
- Explains how to reference Custom Fields and system timestamp fields in your Derived Field calculations.
Example 1 - Gigabytes/second measure
Description and Console Setup
Suppose you run a cloud service which offers your end customers computing capabilities. To implement this service, you want to charge for Products that your end customers consume on the basis of a usage measure in Gigabyte-seconds of processing. To set this up, you can first create two Data Fields of type Measure on a Product Meter that ingest raw data measures:- A Memory MB field, which represents the amount of memory in megabytes allocated to the compute function.
- A Duration field, which represents the length of time the compute function ran for in milliseconds.
- Converts the input to Memory MB, which is in Megabytes (unit: MiBy), to Gigabytes simply by dividing by 1024.
- Converts the input to Duration, which is in milliseconds (unit: ms), to seconds simply by dividing by 1000.
- Multiplies the memory allocation in GiBy by the duration value in secs to give a measure in Gigabyte-seconds (unit: GiBy.s):

Setup using API Call
If you want to create this Meter with the same Data and Derived Fields using an API call, please see our API Reference Create Meter page. Here’s the JSON using this call for the example:Example 2 - Convert GB to MB measure
If you have a Data Field on your Meter that measures gigabytes stored - field code isgigabytes_stored - and you require a megabytes stored measure, then you can create a Measure Derived Field and use:
Calculation: gigabytes_stored*1024
Example 3 - Convert GB and KB to MB measure
Suppose you have a Meter with two Measure Data Fields for:- Gigabytes stored:
gigabytes_stored - Kilobytes stored:
kilobytes_stored
Calculation: (gigabytes_stored*1024) + (kilobytes_stored/1024)
Example 4 - MB-mins measure
Suppose you have a Meter with two Measure Data Fields for:- Stored volume of data in megabytes at point of last backup:
lastbackup_size - Duration since last backup was made in minutes:
lastbackup_duration
Calculation: lastbackup_size * lastbackup_duration
Example 5 - String Derived Field Operations
You can create string Derived Fields which reference Data Fields. Here’s some examples.Concatenation
Suppose you have two string Data Fields on a Meter:- Location, which is a Where field used to identify the country of residence of your customers.
- Type, which is a What field used to identify the type of data check you are performing on your customers.
+ operator in a Derived Field calculation to concatenate the two string fields:

Cast Numeric to String
If you need to cast a numeric Data Field as a string to give a string Derived field, you can do this:
Example 6 - Derived Fields for Product Add-Ons
Suppose you offer a service to manage and process orders and deliveries for online retailers. Your basic pricing model uses a tiered structure on number of orders/deliveries you handle per billing period. You also want to include some product add-ons, which customers can select for on an order-by-order basis. Pricing for an add-on will use a simple unit price model - each billing period customers are charged a fixed price per add-on consumed. To meet this pricing use case, you can create a Derived Field that uses the 3-argument? : ternary operator. This operator evaluates a boolean statement as first argument and yields one value if the statement is TRUE, another value if the statement is FALSE.
In this example:
- We have a string Data Field on a Meter of type What called
packaging_design. - We then create a Derived Field called
package_addonof type Measure, which uses a calculation that references this Data Field:
Calculation: packaging_design=="yes"?1:0
- When an order is placed for processing that takes the add-on,
yesis entered in thepackaging``*_*``designfield.
TRUE or FALSE:
- If the value of
packaging_designisyes, then the statement isTRUEand the value ofpackage_addonis1. - If the value of
packaging_designis notyes, then the statement isFALSEand the value of thepackage_addonis0.
package_addon Derived Field as its target field, and then select SUM for the Aggregation method.
We can extend this example to show how Derived Fields can be used for use cases where you want to price for a combination of product add-ons. Suppose you want to price when an order you process has opted for an express package delivery and gift packaging as a combined product add-on. You can set up two string Data Fields on a Meter of type What:
packaging_expresspackaging_gift
package_addon2 that references these two Data Fields and employs a nested ternary operator:
Calculation: packaging_express=="yes"?(packaging_gift=="yes"?1:0):0
How does this work?
- The nested expression in brackets is evaluated, which will result in
1only ifpackaging_gifthas a value ofyes. - The main expression is then evaluated and results in
1only ifpackaging_expresshas a value ofyesand the nested expression has returned a value of1. If the nested expression has returned0, then the main expression will return0, regardless of whetherpackaging_expresshas a value ofyesor any other value - that is, is eitherTRUEorFALSE.
yes does the Derived Field have a value of 1 returned.
Example 7 - Derived Field for Seat-Based Pricing
Suppose you want to implement usage-based pricing against an end-customer Account which accommodates changes in the number of users on that Account during the billing period. This kind of billing use case is often referred to as “seat-based pricing” and can adjust billing charges in the following way:- If members are added to the Account at any time within the billing cycle, the Account will be charged a prorated amount based on the percentage of the billing cycle left at the time each member was added.
- If members are removed from the Account at any time within the billing cycle, the Account will be credited in a similar, prorated way.
? : ternary operator. This operator evaluates a boolean statement as first argument and yields one value if the statement is TRUE , another value if the statement is FALSE.
Taking a worked example to illustrate how this calculation works, let’s suppose you’ve put an end-customer Account on a Product Plan for monthly billing and you want to charge for seat-based pricing for September, a 30-day month:
- The Account starts the month at 30 seats.
- 1 seat is removed after 8 days.
- 1 seat was added back in after 20 days.
- This means the seat count is back at 30 at the end of the month.
- The charge rate is $10 per month per seat on the Account.
- The
seat-adjustmentsData Field is used to log either the removal or addition of a single seat and sends in an appropriate value for these events throughout the billing period:- A value of -1 when a seat is removed.
- A value of +1 when a seat is added.
- We then create a Derived Field called
seat_prorationof type Measure that references theseat_adjustmentsfield and exploits systemts(timestamp) fields:
Calculation: seat_adjustments * ((ts <= ts.startOfMonth) ? 1 : (ts <= ts.endOfMonth) ? 1 * (((ts.endOfMonth - ts))/(ts.endOfMonth - ts.startOfMonth)) : 0)
For our worked example, we can first manually calculate what the charge amount should be:
- We have an unchanged seat count of 29 for the full month that results in a charge due of: 29 x $10 = $290
- We have a seat count of one that will be charged at the prorate of $10/30 per day for:
- 8 days worth: 8 x $10/30 = $2.67
- 10 days worth: 10 x $10/30 = $3.33
- Total charge: $290 + $2.67 + $3.33 = $296.
seat_proration Derived Field calculation in the context of the worked example and see how the calculation is evaluated to give a correct prorated seat count value for the month:
(ts <= ts.startOfMonth) ? 1- If the
ts(timestamp) for theseat_adjustmentsevent is less than or equal to the start of the month(ts.startOfMonth), the result is 1.
- If the
(ts <= ts.endOfMonth) ? 1 * (((ts.endOfMonth - ts))/(ts.endOfMonth - ts.startOfMonth)) : 0- In our example, the first
seat_adjustmentsevent was sent at the end of the 8th day of the Month and this expression checks whethertsis less than or equal to the end of the month(ts.endOfMonth)which it is. If true, it calculates a weighted value based on the position oftswithin the month:- For the first
seat_adjustmentevent, -1 was sent at the end of the 8th day so the prorated value returned would be -0.73, which represents the reduction in charge due for the 22 days of the month remaining with one seat removed. - For the second
seat_adjustmentevent, +1 was sent at the start of the 21st day so the prorated value returned would be 0.33, which represents the additional charge due for the 10 days of the month remaining with one seat added back in. - This results in a net adjustment of: -0.73 + 0.33 = -0.4
- For the first
- In our example, the first
start_seatcount. This sends a measure of the number of seats registered for the Account at the start of each billing period - in our example, the start of each month. With these two Data Fields in place, we can now add Aggregations to arrive at a pricing metric that accommodates seat count adjustments:
- A simple SUM Aggregation targeting the
start_seatcountData Field. - A simple SUM Aggregation targeting the
seat_prorationDerived Field. - A Compound Aggregation:
adjusted_seatcount, that references these two fields and adds them together them using the following calculation:
Calculation: (aggregation.start``*_*``seatcount`` ``+ aggregation.seat_proration)
- We can now use the
adjusted_seatcountCompound Aggregation to price up Product Plans for those Accounts to which we want to apply seat-based pricing. - In our concrete example, the result of the calculation used for the
adjusted_seatcountCompound Aggregation will be: 30 - 0.4 = 29.60. Therefore the charges for the Account will be: $10 x 29.60 = $296, which agrees with what we calculated manually.