# NPS calculation with metrics

The problem I’m having:
I’m trying to make a metric for NPS calculation but I can’t describe the expression correctly because the results don’t compile.
For example, the expression can’t handle an operation like this: A/B + C/D, because the parenthesis don’t close. Also, everything that goes after the division / is left out from the parenthesis.
I had to make a workaround multiplying from the left side in order to make it work.

The context of why I’m trying to do this:
An NPS calculation which is an operation like this (A+B)/C * 100. This should return the result of the division * 100. But the 100 is calculated before the division occurs, so it returns (A+B) / (100 C).

What I’ve already tried:
100 * (A+B)/C. This worked.

Some example code or error messages

Here are some examples of derived metrics and their compiled code results:
1:

``````calculation_method: derived
expression: "({{ metric('nps_promoters') }} - {{ metric('nps_detractors') }}) / {{ metric('nps_surveys') }} * 100"
``````

Compiled result 1:

``````select
first_join_metrics.*
, ((nps_promoters  / nullif( nps_surveys - nps_detractors) , 0) / nullif( nps_surveys * 100, 0)) as nps_app_bankaya
from first_join_metrics
``````

1 compiles but it does not return the expected result

2: Of the Type (A/B - C/B) * 100

``````calculation_method: derived
expression: "({{ metric('nps_promoters') }} / {{ metric('nps_surveys') }} - {{ metric('nps_detractors') }} / {{ metric('nps_surveys') }}) * 100"
``````

Compiled result 2

``````select
first_join_metrics.*
, ((nps_promoters  / nullif( nps_surveys - nps_detractors , 0) / nullif( nps_surveys) * 100, 0)) as nps_app_bankaya
from first_join_metrics
``````

A/(B - C) / (B * 100)