## Formula Variable is Replaced by the Key of a Characteristic

As explained in Formula Variables, by default such a variable is replaced after aggregation over the reference characteristic. If yo use the Modeling Tools of the HanaStudio to define your queries, it is also possible to change this default behavior by removing the flag 'After Aggregation' for the formula variable. Then, the replacement works basically the same way as for variables of type 'Replaced by Attribute'. In the following we discuss a simple example where we can show the main differences of the settings 'After Aggregation' and 'Before Aggregation'.

### Query where FV is calculated After Aggregation(default)

##### Formula Variable

The formula variable is replaced by the key of 0FISCPER3 and the replacement takes place after aggregation. We use the abbreviation FV2.

##### Query

The sample query contains the formula variable FV2(after aggregation) and another one(FV1) which only differs from the first one in the flag 'After Aggregation'. Always one key figure contains only the formula variable and a second one the formula Counter/FV:

We run the query in Transaction RSRT:

First we focus on the key figures where formula variable FV2(after aggregation) is used:

As explained in Formula Variables, the formula variable is not replaced in the yellow result line since there is no period assigned to theses cells. In case we set the following global filter in the query regarding 0fisper3, the result changes to

Global Filter

### Query where FV is calculated Before Aggregation

##### Formula Variable

Now we take a closer look at the formula variable FV1 where the flag 'After Aggregation' is not set and hence the formula variable is replaced before aggregation as if the values are derived by attribute values of the reference characteristic. Hence, internally the OLAP engine works with the artificial attribute 1ATTRKEY(see Formula Variables).

The query result is now as follows:

The second column only contains the formula variable and hence the aggregation MAX is used(see Formula Variables). The 4th column displays the formula Counter/FV1. You can see that the formula is calculated for each posting period and the aggregated with SUM.