# Key Figures¶

As described in the section about key figure formulas, one of the main differences of key figure structures compared to other structures is the definition of formulas. To be able to support more complex formula systems, the definition of formulas will be separated from the model definition. This section describes the separate initial upload, update and export of these key figure formulas.

## Structure¶

Key figures uploads and exports have the same structure and are specified in JSON.

```
{
"rootCubeSegment": {
"formulas": [
<KEY_FIGURE_FORMULAS_DEFINITION>,
...
],
"segmentation": <SEGMENTATION_DEFINITION>
}
}
```

On the top level, the definition includes the `rootCubeSegment`

property with the following nested properties:

`formulas`

: Contains the formulas defined for the root cube segment. Key figures not present in`formulas`

have no formula. The property is not optional but it may be empty. The order of the entries is not relevant.`segmentation`

: a division of the root segment into smaller segments along a dimension. This property is optional.

### Key Figure Formulas Definition¶

One `KEY_FIGURE_FORMULAS_DEFINITION`

defines the two formulas to be used for a single key figure.

```
{
"keyFigureReference": {
"businessKey": "CST010P"
},
"formulaForLeavesInAllOtherDimensions": <FORMULA_DEFINITION>,
"formulaForInnerNodeInAtLeastOneOtherDimension": <FORMULA_DEFINITION>
}
```

All properties must always be present.

`keyFigureReference.businessKey`

: the business key of the key figure for which the formulas are given`formulaForLeavesInAllOtherDimensions`

: the formula to use for calculations of cells where the elements in all other dimensions are leaves in their hierarchy. This is the equivalent of the`formula`

column in the key figure structure definition (cf. key figure formulas).`formulaForInnerNodeInAtLeastOneOtherDimension`

: the formula to use for calculations of cells where at least one element in another dimension is an inner node in its hierarchy. This is the equivalent of the`formulaForInnerNodes`

column in the key figure structure definition (cf. key figure formulas).

### Formula Definition¶

There are three possible definitions for a formula.

```
{
"type": "NONE"
}
```

If the formula should not be calculated, only the `type`

property must be present and set to `NONE`

.

```
{
"type": "DEFINED",
"formula": "[CST010]/[CST000]*100"
}
```

If the formula should be calculated, the `type`

property must be set to `DEFINED`

and the `formula`

property must contain a non-blank formula string.
This formula string can use the same constructs as previously shown for the
key figure structure definition.

```
{
"type": "INHERITED"
}
```

If the formula definition of the parent segment should be used,
only the `type`

property must be present with a value of `INHERITED`

.
This is not allowed in the root cube segment, since it has no parent segment.

### Segmentation Definition¶

A `SEGMENTATION_DEFINITION`

defines how a cube segment is further divided into multiple child segments.

```
{
"dimensionReference": {
"pluralName": "Cost Centers"
},
"children": [
<CHILD_CUBE_SEGMENT_DEFINITION>,
...
],
"remainder": <REMAINDER_CUBE_SEGMENT_DEFINITION>
}
```

All properties must always be present:

`dimensionReference`

: a reference (by plural name) to the dimension along which the "parent" segment is divided into smaller segments. May not reference the key figure or time dimension.`children`

: an ordered list of child segments, each responsible for some trees in the dimension. May be empty.`remainder`

: a non-optional segment for all elements whose roots were not explicitly included in any of the child segments.

### Child Cube Segment¶

A `CHILD_CUBE_SEGMENT_DEFINITION`

defines a cube segment for some trees in a dimension.

```
{
"structureElementReferences": [
{
"businessKey": "CCT000"
},
...
],
"displayName": "a descriptive display name",
"formulas": [
<KEY_FIGURE_FORMULAS_DEFINITION>,
...
],
"segmentation": <SEGMENTATION_DEFINITION>
}
```

All properties are required

`structureElementReferences`

: references (by business key) to roots of the segmented dimension. All elements inside the trees under the roots are in this segment. May be empty.`displayName`

: a descriptive name for the segment to be displayed in the application`formulas`

: the formulas for this segment. Key figures which are not listed will behave as if they have the type INHERITED for both formulas.`segmentation`

: a further segmentation of this child segment according to a different dimension

### Remainder Cube Segment¶

A `REMAINDER_CUBE_SEGMENT_DEFINITION`

defines a cube segment for all elements in a dimension
that were not explicitly assigned to other child cube segments.

```
{
"displayName": "a descriptive display name",
"formulas": [
<KEY_FIGURE_FORMULAS_DEFINITION>,
...
],
"segmentation": <SEGMENTATION_DEFINITION>
}
```

The properties are the same as in the child cube segment,
except for the missing `structureElementReferences`

property since the structure elements
in the remainder are implicitly defined by the other child cube segments in the segmentation.

## Upload¶

A key figures upload works similar to an asynchronous model upload.
However, for the key figures uploads, we do not employ multipart uploads, but rather use the content type
`application/x.de.qvantum-plan.external-key-figures+json`

to upload a single file.
New uploads can be created at the `keyFiguresUploads`

link in the cube resource
(cf. navigating to a cube).

```
curl -i -X POST \
-H "Authorization:Bearer ${TOKEN}" \
-H "Content-Type:application/x.de.qvantum-plan.external-key-figures+json" \
-d @/absolute/path/to/key-figures.json \
"${KEY_FIGURES_UPLOADS_URL}"
```

The response contains a URL in the `Location`

header.
This URL can be used for status polling.

Important

A full interaction path with the QVANTUM public API regarding key figures
is demonstrated in the script `qvantum-key-figures-import-export.sh`

in our sample data set.

## Export¶

An export of the current key figures is available at the endpoint specified by the
`keyFigures`

link in the cube resource (cf. navigating to a cube).

```
curl -s -X GET \
-H "Authorization:Bearer ${TOKEN}" \
-H "Accept:application/x.de.qvantum-plan.external-key-figures+json" \
"${KEY_FIGURES_URL}"
```

Important

A full interaction path with the QVANTUM public API regarding key figures
is demonstrated in the script `qvantum-key-figures-import-export.sh`

in our sample data set.