Implement a metric as rollup metric


Can I implement a metric as a rollup metric in a simplemetric spec?

i.e. I want to implement weathernormalization for organization (not supported) as a rollup of the metrics results of the org’s underlying facilities


One possibility is to define an actionDecl metric that will call a function defined on the orgs on which you sum the result of the rollups on the children facilities.
Here is an example (assuming you have a metric called FacilitiyMetric and defined at the facility level):

  "id": "FacilitiyMetricRollup_Organization",
  "name": "FacilitiyMetricRollup",
  "srcType": "Organization",
  "variables": [{
    "name": "targetMetric",
    "value": "FacilitiyMetric"
  }, {
    "name": "aggregationFunc",
    "value": "SUM"
  "actionDecl": {
    "action": "rollupFacilityMetric",
    "include": "id"

In Organization.c3typ

remix type Organization {
  rollupFacilityMetric: function(obj: Obj, spec: TSEvalSpec, metric: Metric): Timeseries js server

In Organization.js

function rollupFacilityMetric(obj, spec, metric) {
  var targetMetric = metric.variables.find(function(variable) {
    return === "targetMetric";
  var aggregationFunc = metric.variables.find(function(variable) {
    return === "aggregationFunc";

  if (_.isUndefined(targetMetric) || _.isUndefined(aggregationFunc)) {
    // return an all missing timeseries 
    var length = DateTime.dateDiff(spec.start, spec.end, spec.interval);
    var missing = _.times(length, _.constant(100));
    return NormTimeseriesDouble.make({
      m_start: spec.start,
      m_end: spec.end,
      m_interval: spec.interval,
      m_missing: missing
  // return the rollup 
  return Facility.rollupMetric({
    expressions: ["value")],
    filter: Filter.intersects("parentOrgs", []),
    start: spec.start,
    end: spec.end,
    interval: spec.interval,
    continueOnError: true,
    limit: -1,
    cache: true


Is it possible to replace an actionDecl like the above (rollup) by something declarative/optimizable, i.e., expression or tsDecl?