Returns a LinearFit object calculated from the FactList data points. If a DateRange is provided as a parameter this range is used to filter out data point for the prediction. The predict function uses a linear regression analysis of the metric or KPI facts to enable prediction of future values. A typical use would be to analyse the recent trend, over 7-10 days and use that to provide a prediction of the end of month value for the KPI.

// The list of values
var spent = kpis.get('total budget spent');

// a DateRange for 10 days
var tenDays = now.last10Days();            

// analyse the last 10 days
var predict = spent.predict(tenDays);      

// output the predicted end of of month value
return predict.valueFor(now.endOfMonth());  

When making predictions for an end of month date it is often necessary to be careful with how you treat early predictions. For example, as there is insufficient data in the first day or two of each month the predicted value is unlikely to be helpful. Similarly the final days of the month should gradually trend towards the actual value on the final day of the month. A more sophisticated prediction KPI formula should take these special cases into account.

//Filter the data to the month of the KPI calculation date
var spent = kpis.get('budget spent').filter(now.monthToDate());

//At the end of the month the real value is always correct
if (now.isEndOfMonth()){
    return spent.getLatest();

//later in the month use the last weeks worth of data points to predict
if ( > 15){
    var predict = spent.predict(now.last7days());
    return  predict.valueFor(now.endOfMonth());

//early in the month use all the available data
if ( > 2){
    var predict = spent.predict();
    return  predict.valueFor(now.endOfMonth());

//In the first two days there is no value to the prediction
//As a placeholder why not return last months value?
return kpis.get('budget spent').valueFor(now.startOfMonth().minus(1, ‘d’));

Did this answer your question?