Finally I was able to solve the problem: it was not for the formula, it was for the granularity of data.
In the script I had several conditions which reduced the volume of data.
[...] WHERE Alt (Value, 0)> 0
Removing those conditions the volume of data increased but thus gained granularity.
Thanks aqu for his help.