Charger instructions
Charger instructions turn a transformed fact table into cube output. A Charge job calculates exact measures, applies charging rules, allocates target amounts, and publishes reporting fields. The Transformer must settle the input grain, customer identity, and source reconciliation first.
To build a Charge job in the app, see Chargers.
Top-level keys
| Key | Required | Meaning |
|---|---|---|
$schema | No | Schema identifier. When present, use https://hypermeter.com/charger.schema.json. |
inputs | No | Runtime input definitions used while rendering the template. |
resultSet | No | Legacy private table name. Omit it. |
fact | Yes | Transformed fact table to charge from. |
grain | Yes | Time grain and identity dimensions. See Grain. |
moment | Yes | Start and end moment configuration. |
relationships | Conditional | Declared fact-to-dimension joins. Required when any column uses kind ForeignKey. |
ruleTargets | Conditional | Stable pricing targets, grouping, quantity, and allocation. Required for rule-priced measures. |
dimensions | Yes | Dimension mappings. At least one. |
measures | Yes | Measure mappings. At least one. |
Inputs
| Key | Required | Meaning |
|---|---|---|
name | Yes | Input key. Must start with a lowercase letter and can contain lowercase letters, numbers, _, and -. |
type | No | String, Boolean, Numeric, DateTime, or SecretRef. Defaults to String. |
default | No | Default value when the run does not supply one. |
inputs:
- name: billing_month
type: String
- name: moment_start
type: DateTime
- name: moment_end
type: DateTime
Do not use Extractor concepts such as outputs, matrix, and next in Charger instructions. Pass the values as inputs.
Output and fact table
| Key | Required | Meaning |
|---|---|---|
fact.table | Yes | Transformed fact table that the Charger reads. |
fact:
table: customer_cost_fact
A Charge job has one output, named by the job. A successful run replaces the data of this job for the dates it covers, and new dates add history. Another Charge job always adds its own output. Older instructions may still carry resultSet.table. It names private storage only and does not create a separate output. Do not add it to new instructions.
Grain
Every Charger must define grain. A cube relationship is optional and controls only publication. The cube derives its read-only effective grain from its active Charge jobs.
grain:
time_grain:
granularity: month
timezone: UTC
conventions:
week_start: 0
month_start_day: 1
identity_dimensions:
- Customer ID
- Service ID
| Key | Allowed values |
|---|---|
granularity | hour, day, week, month, quarter, or year. |
timezone | Always set it. The template adds no default. |
week_start | Integer from 0 through 6. Zero is Monday and 6 is Sunday. Always set it. |
month_start_day | Integer from 1 through 28. Always set it. |
identity_dimensions | Names of dimensions in the same instructions. A time-only grain can use an empty list. |
Moment
moment defines the time window and the source columns of the charged rows.
| Key | Required | Meaning |
|---|---|---|
moment.start.timestamp | Yes | RFC3339 timestamp with timezone, or an exact input reference such as ${{ inputs.moment_start }}. |
moment.start.column | Yes | Column object used as the row start moment. |
moment.start.kind | No | Inclusive or Exclusive. A new Charge job has Inclusive. |
moment.end.timestamp | Yes | RFC3339 timestamp with timezone, or an exact input reference such as ${{ inputs.moment_end }}. |
moment.end.column | Yes | Column object used as the row end moment. |
moment.end.kind | No | Inclusive or Exclusive. A new Charge job has Exclusive, for a [start, end) window. |
Recommended monthly pattern:
moment:
start:
timestamp: ${{ inputs.moment_start }}
kind: Inclusive
column:
kind: Direct
name: charge_start
end:
timestamp: ${{ inputs.moment_end }}
kind: Exclusive
column:
kind: Direct
name: charge_end
The FOCUS standard expects an Exclusive window end. A new Charge job starts that way. See Standards and FOCUS.
Column objects
Dimensions, moments, units, and measures use column objects. A column object is not a bare string.
| Kind | Required keys | Meaning |
|---|---|---|
Literal | kind, value | A constant string, number, or boolean. |
Direct | kind, name | A column of the fact table. |
ForeignKey | kind, foreignKeyName, valueColumnName | Follows a join declared in relationships and reads valueColumnName from the referenced table. |
Indirect | kind, source.matchColumnName, reference.tableName, reference.matchColumnName | Matches a fact-table value to a reference table. reference.valueColumnName optionally selects the returned value and defaults to reference.matchColumnName. |
Calculated | kind, name | A previously configured measure. Only valid in measure operand lists. |
FinalAllocatedTarget | kind, targetId | The final row allocation of one target. Only valid for post_allocation measure operands. |
Relationships
A ForeignKey column names a relationship at the top level of the template.
relationships:
- name: azure_nce_fact_partner_id_fkey
sourceColumnNames: [partner_id]
referenceTableName: partner
referenceColumnNames: [id]
| Key | Required | Meaning |
|---|---|---|
name | Yes | Unique name. A ForeignKey column selects it through foreignKeyName. |
sourceColumnNames | Yes | Ordered columns on the fact relation. At least one. |
referenceTableName | Yes | Relation the fact rows reference, in the same schema as the fact. |
referenceColumnNames | Yes | Ordered columns on the referenced relation. At least one. |
The Charger checks these rules before a run starts:
- Every
foreignKeyNameused by a moment, dimension, or measure column must match a declaredname. Otherwise the error names the fact table and the column. - Relationship names must be unique within a template.
sourceColumnNamesandreferenceColumnNamesmust have the same length.
Dimensions
| Key | Required | Meaning |
|---|---|---|
id | Conditional | Stable identity. Required when a rule target refers to this dimension. |
name | Yes | Readable dimension name exposed by the charged output. |
column | Yes | Column object using Literal, Direct, ForeignKey, or Indirect. |
valueType | No | Logical scalar type: string, number, or boolean. Defaults to string. |
dimensions:
- name: Customer ID
column:
kind: Direct
name: customer_id
- name: Line Item ID
column:
kind: Direct
name: line_item_id
- name: Customer
column:
kind: Direct
name: customer_name
- name: Service
column:
kind: Direct
name: service_name
- name: Is Enterprise
valueType: boolean
column:
kind: Direct
name: is_enterprise_dimension
Use stable IDs for identity dimensions, such as customer, contract, subscription, and service-line IDs. Display names can change, so keep them in separate dimensions.
The Charger stores each dimension value as canonical text. Set valueType when a number or boolean dimension must keep its source type for grouping, filtering, category mapping, and semantic fields. Use true or false for booleans and an unformatted decimal string for numbers. Omit valueType for text dimensions.
Measures
| Key | Required | Meaning |
|---|---|---|
id | Conditional | Stable measure identity. Rule targets and calculated references use it. |
name | Yes | Readable measure name. |
kind | Yes | Copy, Sum, Difference, Product, or Ratio. |
columns | Yes | Ordered operands. |
unit | No | Unit definition. Defaults to None. |
labels | No | Exact label map used to freeze matching rule versions. |
phase | No | pre_pricing or post_allocation. Defaults to pre_pricing. |
Operand counts are exact:
| Kind | Operand count | Behavior |
|---|---|---|
Copy | 1 | Copies one operand and preserves its source value domain. |
Sum | 2 or more | Adds operands exactly. |
Difference | 2 or more | Subtracts each later operand from the first. |
Product | 2 or more | Multiplies operands exactly. |
Ratio | 2 | Divides the numerator by the denominator as an exact rational. |
Multiply and Divide are not aliases.
Precision:
- You do not set the result domain, storage type, or quantization profile. Every exact result uses
DECIMAL(38,12)and theexact-12-half-even-v1profile, whatever its unit. - A Currency unit labels the value with its currency. It does not change the arithmetic, and a Currency
Copykeeps all 12 fractional places of its source. - Releases compiled before 2026-11-11 can carry
currency-6-half-away-v1on Currency measures until you activate a new release. - The stored scale does not define the minor unit of a currency or an invoice rounding policy. See Currency values and decimal precision.
- A
Copymeasure keeps an approximate direct source approximate. Such a measure cannot use Currency, pricing labels, or post-allocation inputs. Calculated operations do not accept approximate binary operands. - Literal operands use canonical plain decimal text. Do not use an exponent, leading plus, leading dot, noncanonical leading zero, more than 26 digits before the decimal point, or more than 12 fractional digits.
measures:
- id: price-per-million
name: Price per million
kind: Copy
columns:
- kind: Direct
name: price_per_million
- id: quantity
name: Quantity
kind: Copy
columns:
- kind: Direct
name: quantity
- id: unit-rate
name: Unit rate
kind: Ratio
columns:
- kind: Calculated
name: Price per million
- kind: Literal
value: "1000000"
- id: exact-cost
name: Exact cost
kind: Product
unit:
kind: Currency
column:
kind: Literal
value: USD
columns:
- kind: Calculated
name: Quantity
- kind: Calculated
name: Unit rate
A literal, calculated measure, or final allocated target can be an operand where its phase permits it. A Direct or ForeignKey column can be an operand of a Copy only. To calculate with a source column, Copy it into a measure first, then read that measure as a Calculated operand. FinalAllocatedTarget is valid only in post_allocation.
- id: chargeable-usage
name: Chargeable usage
kind: Copy
columns:
- kind: Direct
name: chargeable_usage
- id: effective-rate
name: Effective rate
kind: Ratio
phase: post_allocation
columns:
- kind: FinalAllocatedTarget
targetId: volume-target
- kind: Calculated
name: Chargeable usage
A Charge job rejects null operands without an operand default, zero Ratio denominators, noncanonical values, and overflow. A failure in any row stops the complete publication.
The denominator of a post_allocation Ratio must be greater than zero in every charged row. In the example above, a row whose chargeable_usage is 0 or -6 stops the run and nothing is charged. See A Charge input was zero or negative.
Operand defaults
A Calculated operand can declare defaultValue: the number that stands for a missing value in that one operand. To default a fact column, Copy it into a measure first, then read that measure as a Calculated operand that declares the default.
Declare a default only when you know what a missing value means. A missing token count means that no tokens were used, so 0 is correct. A missing rate means that the price is unknown, so leave that operand without a default and let the run fail.
- id: uncached-input-tokens
name: Uncached input tokens
kind: Copy
columns:
- kind: Direct
name: uncached_input_tokens
- id: output-tokens
name: Output tokens
kind: Copy
columns:
- kind: Direct
name: output_tokens
- id: total-tokens
name: Total tokens
kind: Sum
columns:
- kind: Calculated
name: Uncached input tokens
defaultValue:
value: "0"
- kind: Calculated
name: Output tokens
defaultValue:
value: "0"
| Key | Required | Meaning |
|---|---|---|
value | Yes | Canonical plain decimal text, under the same rule as a measure literal. |
acknowledgeRateDefault | Conditional | Must be true on a Product operand or a Ratio operand, and is rejected anywhere else. |
Every operand of a Product or Ratio that declares a default needs the acknowledgement, a quantity operand included:
- id: quantity
name: Quantity
kind: Copy
columns:
- kind: Direct
name: quantity
- id: unit-price
name: Unit price
kind: Copy
columns:
- kind: Direct
name: unit_price
- id: exact-cost
name: Exact cost
kind: Product
columns:
- kind: Calculated
name: Quantity
defaultValue:
value: "0"
acknowledgeRateDefault: true
- kind: Calculated
name: Unit price
The Unit price operand declares no default, so a row without a price still stops the run.
Rules:
- Without a default, a missing value in the operand remains an error.
- A default is never SQL null.
- A default uses the value domain of its operand. An exact-integer operand takes integer text, and an exact-decimal operand takes decimal text.
- A
Copymeasure cannot declare a default.Copypreserves its source value, SQL null included. - A
Literal,FinalAllocatedTarget,Direct, orForeignKeyoperand cannot declare a default. - A
Ratiodenominator can default to any non-zero value. A default of zero is rejected. In apost_allocationRatio, a negative default is rejected as well. - A default replaces only a missing value, not a zero or negative value that a row supplies. A
post_allocationRatiorefuses such a denominator at run time, even when the operand declares a positive default. - Defaults apply to row-level operands only. A target aggregation, an allocation weight, and an allocation total-weight window have no
defaultValueand still refuse a null. - A calculated measure whose operand used a default is an ordinary measure result. A target, an allocation weight, or another measure can read it.
- A change to a default takes effect only in a new workflow revision. An active release keeps the defaults it was compiled with.
When a row has no value for an operand without a default, the run fails before it publishes anything. The failed job names the measure, the operand, and the source column, and shows identity values for the rows involved. See A required Charge input was missing.
While you edit, the workflow shows a notice for every calculated-measure operand that reads a nullable column and declares no default. The notice names the measure, the operand, and the column. It never blocks saving, compiling, or running.
Rule targets and allocation
ruleTargets connects a stable measure to pricing and final allocation.
| Key | Required | Meaning |
|---|---|---|
targetId | Yes | Stable target identity. |
measureId | Yes | Stable target measure identity. |
aggregation | Yes | identity or sum. |
groupDimensionIds | Yes | Stable dimensions that define the pricing group. |
quantityMeasureId | Conditional | Exact quantity used by a base schedule. |
allocation | Yes | none or one target-owned proportional policy. |
An identity target prices one source row at a time, so each of its groups must hold exactly one source row. A group is the charge period, the pricing period, and the values of the target's groupDimensionIds together. Rows with no value (SQL NULL) in the same group dimension fall into the same group. Empty text is a value of its own. The run fails when any group holds two or more rows, also when the rows carry equal values. The failure names the target and the group. See An identity target group held more than one source row.
To repair such a template, do one of these:
- Add group dimensions until each group is one source row, for example the line-item or resource ID.
- Aggregate the source in the Transformer, so that it delivers one row per group.
- Change the target to
aggregation: sumwith aproportional_by_measureallocation, which is meant for groups of several rows.
Use none when one group result maps to one row:
allocation:
kind: none
Use proportional_by_measure when one final group amount maps to several rows:
allocation:
kind: proportional_by_measure
weightMeasureId: chargeable-usage
stableBusinessKeyColumns:
- team_id
- cost_center_id
remainderPolicy: largest_remainder_canonical_key_v1
Allocation belongs to the target. A charging rule cannot replace it. The Charger quantizes the group amount before allocation. It assigns the remaining scale-12 units by exact fractional remainder and the canonical business key.
Units
The measure editor offers Number and Currency as its Value type choices. A new Number measure uses unit.kind: None. Currency uses unit.kind: Currency with a fixed code or a produced dimension.
| Unit kind | Required keys | Meaning |
|---|---|---|
None | kind | A number without a currency binding. |
Currency | kind, column | Currency from a literal or produced dimension. Values must be supported ISO 4217 codes. |
Dynamic | kind, column | Existing non-currency unit settings. The editor shows Number and retains the saved settings. |
Metric | kind, column | Existing metric unit settings. The editor shows Number and retains the saved settings. |
Imperial | kind, column | Existing imperial unit settings. The editor shows Number and retains the saved settings. |
Non-currency unit settings do not provide unit conversion or unit-specific report formatting. The Ratio operation keeps its ratio meaning in reports.
Use a literal when every value uses one currency:
unit:
kind: Currency
column:
kind: Literal
value: EUR
Use a column-backed Currency when rows can carry different currencies. Exactly one dimension must produce the same source column, so that the cube can bind the amount to it:
dimensions:
- name: Source Currency
column:
kind: Direct
name: source_currency
measures:
- name: Source Cost
kind: Copy
unit:
kind: Currency
column:
kind: Direct
name: source_currency
columns:
- kind: Direct
name: source_amount
- Fixed currency codes are normalized to uppercase and checked against the supported ISO 4217 codes.
- The editor preserves an existing unit
default, but it offers no fallback control. Reporting does not usedefaultto replace a missing currency. It requires a valid fixed code or a currency dimension.
Authoring diagnostic for a missing Currency unit
Compilation reports a warning when a money measure declares no Currency unit, in two cases:
- A measure has no unit and its source column looks monetary, while the template already has a currency-shaped dimension.
- A measure takes its unit from a currency-shaped column under a non-
Currencykind.
The warning names the measure and the column. The test uses names, so it can miss cases or fire on a measure that is not money. It never blocks editing or publishing. When it does not apply, declare unit.kind: None or leave the measure as it is.
A Currency unit does not change how the measure is calculated. It does give the measure currency value semantics.
You cannot apply it in place after the measure was charged. Saving the corrected template then returns job_template_incompatible_with_logical_cube with Active measure <key> cannot change value semantics in place. To adopt the correction, replace the cube: build a new draft from the corrected template and supersede the old one, as for a grain change. See Publishing and evolving.
The bound column must hold a real ISO 4217 code on every row. Export rejects the whole result when a row carries a blank or a placeholder such as (Unknown). Fix the fallback in the Transformer before you declare Currency.
If the source contains several currencies, keep the source currency dimension, and group or filter by it in reports. Carry the source amount and the exact rate through the Transformer, calculate the converted amount with a Product measure, and keep the exchange-rate evidence. See Currency values.
Charging rules and labels
Charging rules are separate resources. They run after the measures exist and match measures by labels.
Add labels only to a measure that takes part in rule processing. Give the measure a stable id and connect it to one ruleTargets entry. This identity target needs no allocation, and grouping by the line item keeps every group to one source row:
dimensions:
- id: line-item-id
name: Line Item ID
column:
kind: Direct
name: line_item_id
measures:
- id: cost
name: Cost
kind: Copy
labels:
provider: azure
charge: usage
columns:
- kind: Direct
name: cost_amount
ruleTargets:
- targetId: usage-charge
measureId: cost
aggregation: identity
groupDimensionIds:
- line-item-id
allocation:
kind: none
- Rules can apply volume or graduated base pricing and ordered fixed, offset, or percent adjustments.
- A measure without an exact label-map match is not adjusted.
- Hypermeter freezes the matching rule versions when it creates the workflow revision.
- Commercial ranges apply to the billed business period, not to the run time.
- A rule can filter only on a dimension that is in the
groupDimensionIdsof the target. Use rule filters for customer, contract, service, or region targeting.
For the rule and action contract, see the Charging rules reference. For the concepts, see Charging rules.
Full example
$schema: https://hypermeter.com/charger.schema.json
inputs:
- name: moment_start
type: DateTime
- name: moment_end
type: DateTime
grain:
time_grain:
granularity: month
timezone: UTC
conventions:
week_start: 0
month_start_day: 1
identity_dimensions:
- Customer ID
- Subscription ID
- Service
fact:
table: customer_cost_fact
moment:
start:
timestamp: ${{ inputs.moment_start }}
kind: Inclusive
column:
kind: Direct
name: charge_start
end:
timestamp: ${{ inputs.moment_end }}
kind: Exclusive
column:
kind: Direct
name: charge_end
dimensions:
- name: Customer ID
column:
kind: Direct
name: customer_id
- name: Customer
column:
kind: Direct
name: customer_name
- name: Subscription ID
column:
kind: Direct
name: subscription_id
- name: Service
column:
kind: Direct
name: service_name
measures:
- name: Cost
kind: Copy
unit:
kind: Currency
column:
kind: Direct
name: currency
default: USD
columns:
- kind: Direct
name: cost_amount
- name: Source Line Count
kind: Copy
columns:
- kind: Direct
name: source_line_count
Authoring guidance
- Charge one modeled fact table, not a raw source table.
- Create a new Charge job, not a new output name, when a result needs a different cube, grain, or identity.
- Use
post_allocationonly for calculations over final allocated target values. - Put proportional allocation on
ruleTargets, not on individual rules. - Repair the Transformer output when the Charger reports duplicate grain rows, null identity, or overlapping periods.