How can I roll-up metrics of Type B into a metric of Type A?

#1

My goal is to create a metric on Type A which rolls up (averages) the results of a metric called on its children of Type B. I need to end with a metric of Type A because I will use that metric in other compound metrics on Type A. I cannot define the lowest level Simple Metrics on Type A because aggregating the values of the children at this level will yield the wrong values: I need the values of the children to change individually through a series of Metrics before they are aggregated together. Is there a simple (or complex) way to accomplish this functionality?

0 Likes

#2

Unfortunately right now you would need to define the lowest level on type A. You can use the expression function “map” to accomplish this. e.g.

Type A {
  children : [B] (parent)
}

Type B {
  parent: A
  consumption: PhysicalMeasurementSeries
}

{
  id: "averageChildConsumption",
  srcType: TypeA,
  expression: "avg(children.map(sum(measurements.normalized.data.quantity)))"
}

Something like that

0 Likes

#3

Here’s a real life example dealing with energy consumption of a BillingAccount that has multiple contracts for that resource type

{
  "id" : "TotalSpendingOtherCharges_BillingAccount",
  "name" : "TotalSpendingOtherCharges",
  "srcType" : "BillingAccount",
  "expression" : "sum(serviceAgreements.unique().map(sum(normalized.data.otherCharges)))",
  "unit" : {
    "id" : "USD"
  }
}
0 Likes