Download data file for this use case and upload it in your domain.

This tutorial gives you an example how to handle formulas which contain calculations with 'null' result. Otherwise when you are counting with null values the result is always 0.

def a = (filter("L_PRODUCT in ('TV')") {M_SALES})
def b = (filter("L_PRODUCT in ('Radio')") {M_SALES})
def c = (filter("L_PRODUCT in ('PC')") {M_SALES})
if(a == null || a == Double.NaN) {
a = 0
}
if(b == null || b == Double.NaN) {
b = 0
}
if(c == null || c == Double.NaN ) {
c = 0
}
return a/(a + b + c)

 

You can observe result on the visualisations below.

Result:

Before: