Derive revenue and credit events
derive_celGenerates SQL to derive CEL Revenue_Events from subscription or invoice data, or Credit_Events from usage records, using GASP rules for mapped revenue and credit event tables.
Instructions
SQL that derives CEL Revenue_Events from your billing data, or Credit_Events from your usage records, by the rules in the standard (cel.md, 'Deriving Revenue Events from a Subscription Ledger', 'Deriving Revenue Events from an Invoice Ledger' and 'Deriving Credit Events'). Most billing systems hold subscriptions or invoices, not events. source: subscription (default) turns the subscription dataset your mapping covers (subscription_id, customer_id, snapshot_date, mrr, subscription_status, segment, as snapshots at any cadence or a version history) into one revenue_event row per movement: a step is a change in a subscription's active MRR, the ledger's first date is the opening balance, prior_mrr and new_mrr are the customer's MRR chained so prior_mrr + mrr_change = new_mrr holds on every row and the event type (new, expansion, contraction, churn, reactivation) is read from the customer's MRR around the step, with the ATL lifecycle tag, change_nature permanent and an empty expansion_classification (the ledger cannot know it). source: invoice reads the invoice dataset instead (invoice_id, subscription_id, customer_id, snapshot_date, service_period_start, service_period_end, recurring_amount): each invoice is one service period whose MRR is the recurring amount over the months it covers. The same rules apply. Usage above a commitment is Consumption Revenue and no Revenue_Event, so neither source reads the usage records. target: credit_event writes it as credit_event rows instead, from the usage_record dataset (subscription_id, customer_id, period_end, committed_amount, usage_amount): one consumption event with basis overage per usage period over its commitment, dated the period's end, for the overage the period bills, with empty balances (usage within a ratable commitment is no event; a prepaid balance and its expiries come from the billing system's credit ledger). Takes the same mapping as generate_query (a GASP adapter or an Ossie mapping with its semantic_model) and the ledger's currency; the dialect is the one asked for, else the adapter's warehouse, else postgres. Unmapped fields stay as {{field@dataset}} placeholders and are listed. Run the result to build the revenue_event table and map it; the MRR movement metrics compile over it.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"adapter": "<adapter>",
"currency": "<currency>"
},
"name": "derive_cel"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| output | No | 'report' (default): the SQL with the mapping it used, the unmapped fields and what the source can and cannot say; 'sql': the query alone. | |
| source | No | The ledger to read: 'subscription' (default), the subscription dataset as snapshots or a version history; 'invoice', the invoice dataset read as one row per service period (recurring_amount over the months between service_period_start and service_period_end). Use invoice when the billing system keeps no subscription history. | |
| target | No | What to derive: 'revenue_event' (default), the revenue events from the ledger; 'credit_event', one consumption event with basis overage per usage_record period over its commitment, for a company with usage records and no credit ledger (source and first_snapshot are ignored). | |
| adapter | Yes | Your mapping as text: a GASP adapter (JSON; schema: https://gaspwiki.com/schemas/gasp-adapter-v1.json) or an Ossie mapping document (YAML or JSON). It must cover the subscription dataset (the invoice dataset with source: invoice; the usage_record dataset with target: credit_event). Check it with validate_mapping first. | |
| dialect | No | SQL dialect: postgres (also Redshift), snowflake, bigquery or databricks. Omit to use the adapter's warehouse when it names one of them, else postgres. | |
| currency | Yes | ISO 4217 code of the ledger's currency (USD, EUR, GBP ...), written on every derived event. | |
| first_snapshot | No | What the rows on the ledger's first date are. 'opening' (default): opening balances that seed each customer's MRR and produce no event, for a ledger that starts after the oldest subscription. 'steps': steps from 0, for a ledger that starts with the business. | |
| semantic_model | No | With an Ossie mapping: your semantic model document (YAML or JSON), so table names and field expressions resolve. Ignored for a GASP adapter. |