# Error in fillMissing expression

Hi,
I have a issue about the compoundMetric.

I have 3 compound:
A, B, C
where

``````var C = CompoundMetric.make({
"id": "C",
"name": "C",
"expression": "interpolate((A > 2) ? B  : null ,'PREVIOUS','MISSING')"
});
``````

My purpose is to repeat the last of B when `A <= 2`, this seems to work.

If I change my period and set start when `A == 2` this is the result (and it is normal):

What I want now is to fix the missing value of C to some costant value, for example 10.
I see the function f`illMissing(TS,value)` , I declare compoundMetric D:

``````var D = CompoundMetric.make({
"id": "D",
"name": "D",
"expression": "fillMissing(C,10)"
});
``````

and if I try in the same timeRange, seems to work.

PROBLEM:

If I set again the same timeRange in the first figure, when `A <= 2`, it seems as if the `fillMissing` method were added to the `interpolate` Method and return the `PREVIOUS value + fillMissingValue.`

It is a normal behaviour ?

What I’m looking for is this: when `A > 2` use the B value else use the `PREVIOUS` B value, if at the end of this, there is some `null` values (could happen only at the beginning) put it to 10.

how I can fix it?

Thank you

G.

Hi,

This is the expected behavior for `fillMissing()`. It will take the value of the timeseries and add `10 * missingFraction`. So if you have 50% availability it will do `C + 5`. So If you want to fill the value that are missing with a constant I suggest you do the following `available(C) == 100 : C ? identity(10)` and you can adjust the condition if you have fraction of missing values.

Now when you do the interpolation, the interpolated values will be missing so if you just use the code it will also fill the interpolated value with 10. What I suggest you do is first to create a metric to detect when is the first available value of C and use this indicator to fill only the values you want.

Adrien

1 Like

Hi,

The metric proposed by Adrien should be something like that:

`
var E = CompoundMetric.make({
“id”: “E”,
“name”: “E”,
“expression”: “rolling(‘SUM’, available( C )/100 )”
});

var D = CompoundMetric.make({
“id”: “D”,
“name”: “D”,
“expression”: “fillMissing(C, (E==0) ? 10 : 0 )”
});
`

1 Like

Nice solution!
I fix D in this way:

``````var D = CompoundMetric.make({
"id": "D",
"name": "D",
"expression": "(E==0) ? fillMissing(C,10) : C )"
});``````