latestValue(timeseries) through foreign key

Hi all,

I have this type here:

extendable entity type ItemFacility mixes MetricEvaluatable schema name "ITEM_FACILITY" {

  /* Reference to the time series header for inventory and other daily data */
  inventory: [InventorySeries](itemFacility)

/* The latest value for inventoryValue */
  inventoryValue : double stored calc "latestValue("


note: InventorySeries mixes TimeseriesHeader

My stored calc for inventoryValue only works when there is only one InventorySeries id in the inventory array. When there is more than 2 InventorySeries id’s in the field inventory, the stored calc would only work (for one id) if you did something like:
inventoryValue: double stored calc “latestValue(inventory[0].data.value)”

Because we can have 2 timeseries in the foreign key, how can I get the latest value considering both timeseries?

@Sam.Anderson Firstly, the stored calc looks like a very inefficient way to keeping track of the latest value. Imagine instead of 1 or 2 there being 10 headers with millions of data points in it, that stored calc will be updated on every data point upsert and will put a lot of load on the system. So it should definitely not be a stored calc. In general having stored calc on heavy volume types is a bad design.

In order to get the latest value per series you can run: latestValue(

If you want latest values across series then that should be an evaluation via SimpleMetric


   "srcType": "ItemFacility",
   "path": "inventory",
   "id":"LatestValue_ItemFacility", "name" : "LatestValue"

And this should be invoked via ItemFacility.evalMetrics. This implementation will put the lowest overhead on the system and the values will be obtained from the normalized data directly.

If you want this on the type, then one option is to expose it as a function on the type which does the above evalMetric