• james.waugh28 - Thursday, March 30, 2017 3:51 PM

    mark.wojciechowicz@gmail.com - Monday, February 8, 2010 8:33 PM

    Comments posted to this topic are about the item Forecasting with SQL

    Hi Mark, I believe there is an error in your code. When looping and using y = a+bx to forecast yi you are using x(i-1) then adding 1 (i.e. your parenthesis are off) instead of using xi:

    MAX(A) + (MAX(B) * MAX(Forecastkey) + 1), -- Trendline
       (MAX(A) + (MAX(B) * MAX(Forecastkey) + 1))*
       (SELECT ...

    Should be:
    MAX(A) + (MAX(B) * (MAX(Forecastkey) + 1)), -- Trendline
       (MAX(A) + (MAX(B) * (MAX(Forecastkey) + 1)))*
       (SELECT ...

    Outside of this, thanks for the very useful code! Feel free to contact me direct if you'd like to discuss.

    James

    James,
    Thanks for reviewing this and finding the bug.  I have submitted a correction to the article and attachment.
    m