# Weighted average error on recursive analysis

Question asked by GustavoCiuffo on Jun 12, 2018
Latest reply on Jun 13, 2018 by Roger Palmen

Dear all,

I’m working on a few analyses that calculate monthly weighted average for concentrations based on laboratories analysis and accumulated monthly mass.

The formula for the third day, for example is:

MonthlyConcentrationDay3= ((ConcentrationDay1*MassDay1)+(ConcentrationDay2*MassDay2)+(ConcentrationDay3*MassDay3))/( MassDay1+ MassDay3+ MassDay3)

This can be simplified using the previous monthly values, which should already available. Therefore, the generic formula is:

MonthlyConcentrationDayN= ((MonthlyConcentrationDayN-1*AccumulatedMassDayN-1)+(ConcentrationDayN*MassDayN))/(AccumulatedMassDayN).

I’m using the generic version and it works fine when executed daily by the scheduling. However, when recalculated by backfill it fails if the previous day concentration is been calculated on the same backfill iteration leading to “Calc Failed” on the subsequent days.

Besides that, each backfill execution is able to calculate the first day that failed on the previous backfill, leading me to understand that the backfill is “too fast” and doesn’t give data archive enough time to write the calculated value and make it available for the calculation of the next day.

Is it possible to make the analysis wait for the data archive, if the problem is caused by the backfill speed?

The following print is a sample of the actual analysis translated to English. On the actual analysis the last variable is mapped to the attribute "Concentration - Monthly", which is used on the first variable.

Note: All the attributes are Pi Points and the daily and monthly mass attributes are calculated by previous analysis.

Thank you,

Gustavo