Compound Aggregations allow you to derive numerical measures from usage data by applying a calculation to one or more simple Aggregations. The calculation can also reference Custom Fields. You can then use these derived measures to set up usage-based pricing Plans for your Products. In this way, Compound Aggregations can help you to implement a wide range of pricing use cases for your Products.
This topic illustrates the value of using Compound Aggregations with an example use case. It then explains how to create a Compound Aggregation to apply a calculation to simple Aggregations to satisfy the example use case.
Creating Simple Aggregations? We strongly recommend that you create some simple Aggregations and are familiar with their purpose and their configuration as helpful preparation to creating and using Compound Aggregations. See Reviewing Aggregation Options.
Tip: Compound Aggregations - the "Complexity Crunchers" - see more! By exploiting the powerful m3ter Calculation Engine, there's virtually no limit to the flexibility Compound Aggregations give you for defining your precise pricing metrics. To see some worked examples of Compound Aggregations that illustrate how Compound Aggregations can quickly help you resolve complex UBP use cases, please review the Compound Aggregations - Examples and Syntax topic.
Suppose you provide a service which allows your customers to develop and run software applications and host these applications on your service. You intend to charge customers for this application build-and-host service by total number of requests made to all of their applications being hosted in any given billing period. However, you want to offer customers a sign-up bonus for their first year of using your service, where the first 100 requests made to an application they host with you are free for each billing period - for example, if a customer has 3 applications hosted with you during the first billing period, they are due 300 free requests for the first Bill.
To set things up in m3ter to implement usage-based pricing for this type of case, you can use a Compound Aggregation:
First, create and configure a Meter which will record the number of applications hosted. You can send an event into m3ter each time one of your customers creates and loads an application into your service. Use this Meter field to create a simple Aggregation to give a maximum value (MAX) measure for hosted applications. Give this simple Aggregation a code of: unique_apps. (Note that for the example, we suppose that under the terms of the sign-up bonus if a customer reaches 5 applications in any given billing period, they are granted 500 free requests even if 2 of those applications are disabled before the end of the billing period.)
Second, create and configure a Meter to record the number of requests made by applications. You can then create a second simple Aggregation to SUM this data. Give this simple Aggregation a Code of: num_requests.
Third, create a Compound Aggregation that applies a calculation to the two simple Aggregations to give a number for chargeable requests:
Math.max(0, aggregation.num_requests - (aggregation.unique_apps * 100))
When you come to price up your Product Plans, you can now use this Compound Aggregation.
Tip: Calculation Expression - Referencing simple Aggregations and Supported Syntax? For details of how to reference the values of simple Aggregations in calculation expressions and the supported syntax, see below Compound Aggregations - Referencing Values and Fields and Supported Syntax.
This section explains how to create a new Compound Aggregation for the example use case outlined above, and assumes the two simple Aggregations used have already been created for the Product.
To create a Compound Aggregation:
1. Select Usage>Compound Aggregations. The Compound Aggregations page opens.
2. In the Product drop-down, select the Product for which you want to create the new Compound Aggregation.
Tip: Global Compound Aggregation? You can create a Global Compound Aggregation, which is not tied to a specific Product if you want to charge across several Products on the basis of the Compound Aggregation. If you remove the selection, (Global) will show for Product. The simple Aggregations you can reference when you create a Global Compound Aggregation are different to the simple Aggregations you can reference when you create a Product-specific Compound Aggregation - for details, see below Compound Aggregations - Referencing Values and Fields and Supported Syntax.
3. Select Create Compound Aggregation. The Create page opens:
4. Enter the details of the new Compound Aggregation:
Name. For this example, enter a descriptive name, such as Requests minus free.
Code. Unique identifier. For this example, we've used requests_minus_free.
Calculation. First select Advanced for the type of calculation you want to use. Enter the expression for the required calculation using simple Aggregations:
Math.max(0, aggregation.num_requests - (aggregation.unique_apps * 100))
Tip: Calculation Type? If you want to create a Compound Aggregation by merely adding two or more simple Aggregations, you can leave the type selection at the default Add aggregations. You can then use a drop-down to select the simple Aggregations you want to add together. Note that Add aggregations is searchable - if your start to type the name of a simple Aggregation, the list of available simple Aggregations is filtered.
Unit. For this example, enter Requests. This will be used as a label for billing to indicate to your customers what they are being charged for
Rounding. For this example, enter None.
Quantity per Unit. For this example, enter 1.
Evaluate Null Aggregations. Optional field - enable this field if you want to allow null values from the simple Aggregations referenced in the Compound Aggregation to be passed in. Simple Aggregations based on Meter Target Fields where no usage data is available will have null values. Default is to have this disabled.
Tip: Set Default Values of Simple Aggregations to 0. If any of the simple Aggregations you reference in your Compound Aggregation calculation might have null values, you must set their Default Value to 0. This ensures that any null values passed into the Compound Aggregation are passed in correctly with value = 0.
5. Add any required Custom Fields to the Compound Aggregation. For more on Custom Fields, see Adding and Editing Custom Fields. We strongly recommend reviewing Working with Custom Fields before you create and use Custom Fields.
Important! Compound Aggregation Custom Fields not supported for calculations. Creating Custom Fields for Compound Aggregations is intended to support financial reporting use cases. Although you can define Custom Fields at both the Organizational level and individual Compound Aggregation level, they are not supported for use in Derived Field and Compound Aggregation calculations.
6. Select Create Compound Aggregation. You are returned to the Compound Aggregations page where your new Compound Aggregation is listed. Note also that any new Compound Aggregations you've created become immediately available for pricing up your Product Plans. See Pricing Plans and Plan Templates.
Important: Create Simple Aggregations First! If you try to create a Compound Aggregation and you enter a Calculation that references a simple Aggregation that you have not yet created for your Product, you won't be able to save the Compound Aggregation and an error message will show.
This section explains the syntax for referencing simple Aggregation values and Custom Fields in your Compound Aggregation calculations.
Tip: Full Details? Before you start to write Compound Aggregation calculations, we recommend you review the full details of the syntax and supported functions, variables, and operators you can use in you Compound Aggregation calculations at: Calculations Syntax and Supported Functions/Operators.
You can reference the resultant values of simple Aggregations in a Compound Aggregation calculation using a simple Aggregation's Code. The general format is:
You can reference Segmented Aggregations in a Compound Aggregation. The segments defined for the referenced Aggregations that are made available the Compound Aggregation depends on whether it references one or many Segmented Aggregations - see Compound Aggregations - Segments Available.
The simple Aggregations you can reference when you create a Global Compound Aggregation are different to the simple Aggregations you can reference when you create a Product-specific Compound Aggregation:
Global Compound Aggregation. The calculation can reference all simple Aggregations – any Global and all Product-specific simple Aggregations.
Product-specific Compound Aggregation. The calculation can reference the simple Aggregations in the same Product and any Global simple Aggregations.
You can reference the default values for Custom Fields - those defined at Organization level - in your Compound Aggregation calculations:
Next: Segmented Aggregations