Working with Meter Derived Fields and Examples - m3ter Documentation

Documentation Index

Fetch the complete documentation index at: /llms.txt

Use this file to discover all available pages before exploring further.

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:

Important!

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:

Referencing Custom Fields

You can define Custom Fields for your Organization and for the following entity types:

Note that you can define a Custom Field for any of these entities at both the Organizational level and at the level of the individual entity:

However, restrictions apply to the Custom Fields you can reference in a Derived Field calculation. See Referencing Custom Fields in Derived Field Calculations for details.

Important! If you want to use the value of a Custom Field you’ve defined at an individual entity level, you must first define a Custom Field for the entity type at the Organizational level with a default value. For more details, see Working with Custom Fields.

Important! You can also define Custom Fields for Aggregations and Compound Aggregations. However, these Custom Fields are NOT supported for referencing in Derived Field calculations.

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 now reference the Custom Field in your calculation:

The calculation will now be evaluated across the five Accounts using these values:

Format for Referencing Custom Fields

Here’s the general format to use when referencing Custom Fields:

Tip: Global vs. Product Meters? Note that Global Meters - those not associated with a Product - cannot resolve Product-scoped Custom Fields, therefore the default will be used. Meters that are associated to a Product can use the Product-specific Custom Field value if it is defined.

Tip: See Also? For creating Custom Fields in the Console, see Managing your Organization. You can use the Create/Edit Console pages for individual entities to set up Custom Fields. For API calls, see the CustomField section of our API Ref Docs. For more background on Custom Fields, see Working with Custom Fields.

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:

If the “ets” field - End Timestamp - is specified in the measurement, the following are also available:

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:

In addition to concrete examples, the final section in this topic:

Tip: String Derived Fields? Yes, you can also create non-numeric, string Derived Fields which reference Data Fields. See Example 5 below for some examples of operations to create string Derived Fields.

Important: Updating the Calculation? When you use a Derived Field, the calculation is performed at the time the data is ingested and is persisted in the platform at the resultant values. This means that if you update the calculation at a later date:

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:

You can then create a Derived Field of type Measure on your Product Meter that:

You can now use this Meter’s GB Second Derived Field as the basis for setting up an Aggregation for pricing your Product Plans.

Important! Note that when you reference Data Fields in a Derived Field calculation, you must use the Code of the referenced fields.

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:

{
   "data": [
       {
           "id": "3ddfea4b-XXXX-467d-XXXX-b6YYYYYYYYYf",
           "version": 1,
           "productId": "1b364e59-e32b-4fbf-bc1e-91b5fc4872e5",
           "name": "Compute Execution",
           "code": "compute_execution",
           "dataFields": [
               {
                   "category": "MEASURE",
                   "code": "memory_mb",
                   "name": "Memory MB",
                   "unit": "MiBy"
               },
               {
                   "category": "MEASURE",
                   "code": "duration_ms",
                   "name": "Duration",
                   "unit": "ms"
               }
           ],
           "derivedFields": [
               {
                   "category": "MEASURE",
                   "code": "gb_second",
                   "name": "GB second",
                   "unit": "GiBy.s",
                   "calculation": "(memory_mb/1024)*(duration_ms/1000)"
               }
           ]
       }
   ]
}

Example 2 - Convert GB to MB measure

If you have a Data Field on your Meter that measures gigabytes stored - field code is gigabytes_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:

If you require a megabytes stored measure that combines these two, then you can create a Measure Derived Field and use:

Calculation:(gigabytes_stored*1024) + (kilobytes_stored/1024)

Example 4 - MB-mins measure

Suppose you have a Meter with two Measure Data Fields for:

If you require a MB-mins measure, you can create a Measure Derived Field and use:

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:

However, you want a field that combines both these string data types - Location Type. To do this, you can use the + 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:

Tip: String Manipulation Functions? You can also use String functions in your Derived Field calculations - see String Functions for a listing and explanations.

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:

Calculation:packaging_design=="yes"?1:0

The calculation evaluates the first argument to return TRUE or FALSE:

For pricing, we can now set up an Aggregation that uses the 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:

You can then use a calculation for a Derived Field of type Measure called 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?

We can therefore see how this form of calculation is useful when we want to price for multiple product add-ons as a bundled add-on - only if all referenced Data Fields have a value of yes does the Derived Field have a value of 1 returned.

Example 7 - Derived Field for Seat-Based Pricing

Note: Using the m3ter Recurring Charges for Counters feature! You can also implement seat-based pricing for your products and services out-of-the-box using m3ter’s Recurring Charges for Counters feature. See Recurring Charges: Counters for more details.

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:

You can implement seat-based pricing using a Derived Field calculation 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. 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:

For this example:

For our worked example, we can first manually calculate what the charge amount should be:

We can now breakdown the 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:

To implement pricing on the Account, we create another Data Field on another Meter: 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:

In summary, the Derived Field for implementing seat-base pricing calculates a prorated value based on the position of a timestamp (ts) within a month provided by the remove/add usage event.