Period Metrics
Overview
Period Metrics is a special record type that stores JSON configuration for automated period-based data calculations. This configuration defines which records to query, which fields to calculate, what type of calculation to run (count, sum, average, or snapshot), and which time intervals to use for the data.
Once configured, Period Metrics enables a daily scheduled workflow that automatically calculates and populates data across all period entries based on your defined metrics. Period recordings are then generated to capture these calculated values over time.
Core Records
The Period Recording adds four core records to the Clevero instance:
| Record | Purpose |
|---|---|
| Years | Stores yearly entries. This is the starting point for generating all child period and quarter records. |
| Quarters | Stores quarterly entries. These are automatically generated from a Year record by a workflow. |
| Periods | Stores individual period entries, such as weekly or monthly periods. These are automatically generated from a Year record by a workflow. Calculated metrics are stored here. |
| Period Metrics | A single configuration record that holds the JSON object defining what data is calculated. This is the primary configuration record for the feature. |
Custom Fields Setup
Before configuring the JSON, create custom fields on your records. Each calculation needs a field to store its value in.
For example, if you want to store an invoice count, create a field called invoice-count on your records. Field types to create:
- Number fields: For counts and totals
- Currency fields: For money amounts
Workflows
The Period Recording module includes three workflows:
| Workflow Name | Trigger | Purpose |
|---|---|---|
| Generate Quarters and Periods from Year Entry | Button (on Year record) | Automatically creates all Quarter and Period entries for a given year based on its start and end dates. |
| Periods - Update Period Metrics | Scheduled (daily) | Reads the Period Metrics JSON configuration and calculates and populates data across all active Period, Quarter, and Year entries. |
| Create Period, Quarter, and Year Entries | TBC | Creates Period, Quarter, and Year entries. |
JSON Configuration
The Period Metrics record holds a JSON array that defines all calculations. Each object in the array targets a specific record and lists the calculations to run against it.
Top-Level Structure
Each item in the array represents one record source and contains:
record: The API name of the record to query.dateField: The date field used to filter records into the correct period. This is not required for snapshot calculations.calculations: An array of calculation objects.
Calculation Types
| Type | Purpose |
|---|---|
count | Counts the number of records that match the period and any specified filters. |
sum | Sums the value of a specified field across matching records. Requires sumField. |
average | Calculates the average value of a specified field. Requires averageField. |
snapshot | When snapshot: true is set, the calculation only runs during the active period. Once the period ends, the value is locked and is not recalculated. Use this for metrics where you want to capture a point-in-time value, such as current MRR or active customer count. |
Calculation Options
| Option | Purpose |
|---|---|
fieldToStoreValue | The API name of the field on the Period record where the result will be written. Required for all calculation types. |
sumField | The API name of the field to sum. Required for type: sum. |
averageField | The API name of the field to average. Required for type: average. |
updateQuarterly | If true, the same calculation is also written to the Quarter record. Defaults to false. |
updateYearly | If true, the same calculation is also written to the Year record. Defaults to false. |
ImportantThe API name of each field must exactly match the
fieldToStoreValuevalue used in the JSON configuration. Field API names are case-sensitive.If
updateQuarterlyorupdateYearlyis set totrue, the corresponding field must also exist on the Quarters or Years record.
Filters
Each calculation can optionally include a filters array to narrow down which records are included. Each filter object contains:
| Parameter | Description |
|---|---|
field | The API name of the field to filter on. |
operator | The comparison operator, such as contains or not_empty. |
value | The value to compare against. Omit this for operators such as not_empty. |
type | Typically "array" for multi-select or relationship fields. |
Full JSON Example
The following is an example configuration covering multiple record types, calculation types, filters, and snapshot usage:
[
{
"record": "support-requests",
"dateField": "issued-at",
"calculations": [
{
"type": "count",
"options": {
"fieldToStoreValue": "support-case-count",
"updateQuarterly": false,
"updateYearly": false
}
},
{
"type": "count",
"options": {
"fieldToStoreValue": "test-field"
},
"filters": [
{
"field": "parent-support-case",
"operator": "not_empty",
"type": "array"
}
]
}
]
},
{
"record": "kalysys-invoices",
"dateField": "date-issued",
"calculations": [
{
"type": "count",
"options": {
"fieldToStoreValue": "invoice-count",
"updateQuarterly": true,
"updateYearly": true
}
},
{
"type": "sum",
"options": {
"sumField": "net-total",
"fieldToStoreValue": "invoice-total",
"updateQuarterly": true,
"updateYearly": true
}
},
{
"type": "average",
"options": {
"averageField": "net-total",
"fieldToStoreValue": "invoice-average",
"updateQuarterly": true,
"updateYearly": true
}
},
{
"type": "sum",
"options": {
"sumField": "net-total",
"fieldToStoreValue": "subscription-revenue"
},
"filters": [
{
"field": "invoice-type",
"operator": "contains",
"value": 1672706,
"type": "array"
}
]
}
]
},
{
"record": "clevero-subscriptions",
"calculations": [
{
"type": "count",
"snapshot": true,
"options": {
"fieldToStoreValue": "current-customers"
},
"filters": [
{
"field": "status",
"operator": "contains",
"value": 293227,
"type": "array"
}
]
},
{
"type": "sum",
"snapshot": true,
"options": {
"fieldToStoreValue": "current-mrr",
"sumField": "mrr-net"
},
"filters": [
{
"field": "status",
"operator": "contains",
"value": 293227,
"type": "array"
}
]
}
]
}
]Implementation Steps
Step 1: Add the Module to the Instance
Navigate to the client's Clevero instance and add the Period Recording module. This installs the four records: Years, Quarters, Periods, and Period Metrics. The associated workflows are also installed in the system.
Step 2: Create Required Custom Fields
- Identify all the metrics the client wants to track. For each metric, create the appropriate custom field on the relevant record:
- Periods record: required for all calculations
- Quarters record — required if
updateQuarterly: trueis set - Years record — required if
updateYearly: trueis set
- Make sure the API name of each field exactly matches the
fieldToStoreValuevalue you plan to use in the JSON configuration.
Step 3: Create a Year Entry
- Navigate to the Years record and create a new entry for the relevant year.
- Set the start date and end date for the year. The workflow uses this entry to automatically generate all quarters and periods for that year.
Step 4: Run the Generate Quarters and Periods Workflow
With the Year entry open, trigger the button workflow:
- Open the Year entry.
- Click the button to run [SC-07353] Generate Quarters and Periods from Year Entry.
- The workflow automatically creates all Quarter and Period records for that year based on the start and end dates.
Step 5: Configure the Period Metrics JSON
- Open the Period Metrics record and update the JSON configuration field.
- This is the core configuration that drives all calculations. See the JSON Configuration section for full details and examples.
Step 6: Activate the Daily Scheduled Workflow
- Make sure the Periods - Update Period Metrics scheduled workflow is active. This workflow runs daily and performs all calculations defined in the Period Metrics JSON, writing the results to the appropriate Period, Quarter, and Year records.
- Confirm that the workflow is set to Active in the workflow settings.
📌 Need Help?
Updated about 2 hours ago
