7 Replies Latest reply: Sep 13, 2018 2:27 AM by David Štorek

# Calculations based on synthetic dimension

Hi experts,

could you help me a little bit with following task?

I have to create 3 values (Energy cost, Penalty, Reserved capacity) two of them should be calculated based on user defined variables values (Penalty and Reserved capacity) so it must be done on frontend.

My question is what am I doing wrong, that calculation for Penalty does not work with synthetic dimension (expression as itself should be correct, based on that in other objects it works).

Maybe it is some stupis typo, but I am not able to get it work.

For details see atached app.

• ###### Re: Calculations based on synthetic dimension

Could you share the expression/how your calculating the dimension ? currently I don't have access for Qliksense ...if you share the expression we could help

• ###### Re: Calculations based on synthetic dimension

Hi,

dimesion:

```ValueList('Energy cost','Reserved capacity cost','Penalty')
```

measure:

```If(ValueList('Energy cost','Reserved capacity cost','Penalty')='Energy cost',Sum(EnergyConsumption)*\$(vCost),
If(ValueList('Energy cost','Reserved capacity cost','Penalty')='Penalty',Sum(If((aggr(ConsumptionPeak,[Year - Month])/0.25)>(vMonthCapacity+vYearCapacity),(aggr(ConsumptionPeak,[Year - Month])/0.25)-(vMonthCapacity+vYearCapacity),0))*vPenalty,
If(ValueList('Energy cost','Reserved capacity cost','Penalty')='Reserved capacity cost',\$(vMonthCapacity)*\$(PriceOfMonthCapacity)+\$(vYearCapacity)*\$(vPriceOfYearCapacity))))
```
• ###### Re: Calculations based on synthetic dimension

Is the other place where the expression works inside a chart or table with dimensions? Perhaps you have a field value aggregate that is defined in this context, but does not work in a global context.

Test the expression in a text box. If it works there, it should work in the ValueList expression.

Its hard to debug the expression when it contains embedded variables.

• ###### Re: Calculations based on synthetic dimension

Yes it should work but it does not. I works in both text field and KPI object. It shows something different than 0 if I use this expression in combination with some dimension.

Only where it does not work and I realy want it to is in this chart. It seems to be defined in global context.

Even if I change variables to numbers it is not getting better. (btw. variables are just numbers)

Any other ideas

• ###### Re: Calculations based on synthetic dimension

>>It shows something different than 0 if I use this expression in combination with some dimension.

Do you mean 'some selection'? Does the chart version not behave in the same way? As you have observed, the ValueList() dimension does not create a local context like a field dimension, so the expression is evaluated in the same context as the KPI object. I do not see why they would be different.

• ###### Re: Calculations based on synthetic dimension

avinashelite any inputs?

• ###### Re: Calculations based on synthetic dimension

Hi all,

I solved the problem. Using synthetic dimensioun would require to adjust data model because of field ConsumptionPeak (which contains also null values).

To create bar chart with current data model it requires to use dummy dimension and three measures. The result is as required.