# Show values from related objects

AI agent getting started? Read [Agents: start here](https://docs.openeng.io/agents/start-here.md) first.

Display linked counts, totals and shares in a view.

Source: https://docs.openeng.io/configure/calculations/

Use linked calculations to show a component count, a mass total or the share of completed work beside the object being reviewed. The calculation follows relationships from the displayed record.

## Counts, values and shares from linked objects

A calculation element supplies a value for display. A linked-object calculation component (`Aggregate`) supplies a value to a statistic display component (`Stat`); its `aggregate` prop refers to that calculation element. A Stat takes either `aggregate` or `value`. Put both elements in the same
object view, or in the same app Table’s context for one row. A Table Column (a collection-table layout component) has one cell template: use
a layout container (`Stack`, with a column direction) inside the Column to hold the Aggregate and its Stat. Lists, standalone app Stats and
app pages cannot bind Aggregate parts.

Aggregate props are limited to `reach` (which relationships to follow), `measure` (what to calculate) and `ends` (which objects to count); all three are required. For example,
this complete object view counts readable components linked from the displayed object, assuming
the named types and edge exist:

```json
{
  "root": "body",
  "elements": {
    "body": { "type": "ObjectBody", "props": {}, "children": ["part", "stat"] },
    "part": {
      "type": "Aggregate",
      "props": {
        "reach": {
          "kind": "path",
          "hops": [
            { "edgeTypeKey": "uses", "direction": "outgoing", "targetTypeKey": "component" }
          ]
        },
        "measure": { "op": "count" },
        "ends": "visible"
      },
      "children": []
    },
    "stat": {
      "type": "Stat",
      "props": { "aggregate": "part", "label": "Components" },
      "children": []
    }
  }
}
```

## Choose a traversal

A path takes one to three connected hops; a value measure on a path may name only the final
target type in `over`. Each hop requires `edgeTypeKey`, `direction` and
`targetTypeKey`, and may add `filters` using the object-set filter shapes on the type at the other end of the hop.
Traceability directions are `outgoing` and `incoming`; structural directions are `to-children`
and `to-parent`, interpreted from the edge type's declared parent end.

An object view or Table column may instead use this depth-limited recursive traversal:

```json
{
  "kind": "repeat",
  "edgeTypeKeys": ["uses"],
  "direction": "outgoing",
  "depth": 3,
  "multiplicity": "distinct"
}
```

A depth-limited recursive traversal requires one to eight edge type keys, a direction, depth from one to three, and
`multiplicity` of `per-path` (count each path occurrence) or `distinct` (count each unique object). It takes no filters or target type keys. The start
object never contributes. Each Table cell shows the warnings for its own row: deeper levels,
missing contributor values and paths without weights.

## Choose a measure

The supported measure objects are:

| Measure | Fields and restrictions |
|---|---|
| Count | `{"op":"count"}`; on a repeat only, optional `over` with one to eight reached type keys narrows contributors. Distinct repeat multiplicity counts each object once. |
| Numeric value | `{"op":"sum","property":"mass","over":["component"]}`; `min` and `max` take the same fields. The property must be numeric on the one to eight reached types in `over`. A repeat sum uses the reach's multiplicity. |
| Weighted sum | `{"op":"weightedSum","property":"mass","weight":"quantity","over":["component"]}`; repeat with `per-path` multiplicity only. `weight` names a numeric edge property. Omit `property` to sum the path weights alone. |
| Share | `{"op":"share","where":[{"kind":"property","property":"status","op":"=","value":"complete"}]}`; path only. `where` is a nonempty list of filters on the type at the end of the path. The value is the matching count divided by the count before these extra filters. |

## Handle missing or unreadable contributors

`ends` is `visible` (count readable objects only) or `all` (also report unreadable-object counts; numeric values still use readable objects). Measure values use readable objects; `all` also supplies separate
hidden counts. A count of connected objects you cannot read deduplicates destination objects including project, so parallel links
to one hidden object count once. The runtime shows loading, rejections (platform refusal reasons), no linked contributors and
repeat diagnostics distinctly.

## Use a calculation in a table

Each row starts from the object returned by the Table's Query. Keep its Aggregate and Stat in the same row context. Put them in a Stack inside the Column's single cell template.

## Use a value in another expression

In an object view, a derived definition (a calculated-value expression) may list Aggregate element ids in `parts` and read an
expression such as `{"op":"part","id":"linked-count","field":"value"}`. The fields are
`value`, `hidden` (numeric count) and `deeper` (whether more of the walk exists beyond the requested depth). A loading or rejected calculation produces
`part-unavailable` (the calculation is not available), carrying its id and state instead of an invented numeric value.
