Skip to main content
How energy costs are calculated vary not only across System Operators, but also over time, energy consumption levels, power usage and so on. A given metering point may have one set of calculations one day, and a different set the next as rules are changed. There is also a very wide range of calculations, with market parties broadly left up to their own devices to invent rate “algorithms’. Calculation pipelines are a minimal algebra that abstracts this away - as new tariffs are invented or you enter new markets, your code keeps working. This lets you build systems that require much less maintenance than manually implementing and updating hundreds of tariffs. The calculation pipelines are a sequential list of a small set of Functions, each taking zero or more input Datasets, and producing a single output Dataset. Evaluating each function in order will give you the final cost dataset.
For the technically curious, the calculation pipeline is a form of Static Single Assignment representation — each step assigns a new named dataset, which then serves as input for later steps.
Pipelines usually start with one or more well-known Registered Datasets. Those are datasets that you’ll need to provide to the calculation, like how much energy was or will be consumed per quarter-hour.

Example pipelines

Lets walk through a series of increasingly powerful examples to help get a feel for how the pipelines express different cost structures. Note each example is available as a diagram and as the equivalent JSON representation. The diagrams are available in LLM-readable mermaid diagrams in llms-full.txt.

Example: Fixed monthly fee

This is likely the very simplest example we can give: Each month, the metering point is billed some fixed fee. The fee is the same independent of what the metering point does, so there are no Registered Datasets needed. The pipeline consists of a single Constant Function which outputs a fixed cost per month.

Example: Energy tax

Lets take it a step further and do a calculation that does depend on what the Metering Point does. The energy tax in Sweden is calculated based on hourly kWh consumed. There is no Registered Datasets for hourly energy consumed, as energy consumption at the meter is tracked quarter-hourly. Therefore we combine two functions:
  1. Aggregate the quarter-hour consumption data to hourly by summing it
  2. Multiply the hourly consumption data by the energy tax cost to get the final cost

Example: Peak tariff

Some rate plans charge you for “peak” usage - but what exactly is a “peak”? Unfortunately that depends on which System Operators you ask. This example shows a simplified peak calculation:
  • In each month, find the three highest hourly peaks
  • Take the average of those three
  • Multiply that average with some fee
To do this we:
  1. Aggregate the quarter-hour consumption data to hourly kWh by summing it
  2. Divide the hourly energy consumption data by 1 hour to convert to kW (yes yes, but otherwise we would have needed to add a separate ‘conversion’ operator you know)
  3. Select the 3 highest values per month (see Absent Values)
  4. Aggregate to monthly peaks by taking the mean of those 3 peaks
  5. Multiply the monthly peak value by the fee to get the final cost