SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Forecasting with SQL


Forecasting with SQL

Author
Message
Chad Downey
Chad Downey
Grasshopper
Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)

Group: General Forum Members
Points: 16 Visits: 151
Hi Mark,

Nice article on forecasting using T-SQL! I know it's been a while since you wrote this article but wanted to know if you think this technique would work with a scenario I am faced with on a project.

My scenario is a table of risks with a value for severity, probability and a criticality index value. I would like to predict or forecast the number of risks most likely on the fly so not stored in a table for a charting solution. Basically, I would chart the actual values and then based upon a choosen date display the forecast values to the right and the actual values to the left of the choosen date.

As of now I am rolling up the number of risks by a category or risk type for a monthly rollup which works fine. I'd like to take this data and then do a forecast for future months like you do in this article for say 6 to 12 months ahead from a choosen (parameter) now date.

So in your article you use products and in my scenario I have risks. Do you think I could use this technique to do the forecasts? The forecasts would only have to project an integer or count value based on the historical number of risks in previous months of a project.


Thanks in advance!

Chad E. Downey, CDMP - Certified Data Management Professional
Consultant - SQL Server, SSIS, SSRS, SSAS
mark.wojciechowicz@gmail.com
mark.wojciechowicz@gmail.com
SSC Rookie
SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)

Group: General Forum Members
Points: 44 Visits: 587
Yes. That should work fine for you to give a directional insight into your data. Products, customers or risk types are simply discrete values by which to partition the forecast to make it more useful. Any type of discrete data can be plugged in.

Good luck and have fun exploring forecasting!
Mark
Saravanan_tvr
Saravanan_tvr
SSC-Addicted
SSC-Addicted (424 reputation)SSC-Addicted (424 reputation)SSC-Addicted (424 reputation)SSC-Addicted (424 reputation)SSC-Addicted (424 reputation)SSC-Addicted (424 reputation)SSC-Addicted (424 reputation)SSC-Addicted (424 reputation)

Group: General Forum Members
Points: 424 Visits: 1349
Its very useful for the beginner. If the same sample, if available using SSAS would be great...

Many Thanks!
S.saravanan
“I am a slow walker, but I never walk backwards-
Abraham Lincoln”
Bigtoerag
Bigtoerag
Forum Newbie
Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)

Group: General Forum Members
Points: 9 Visits: 12
Mark Lovely work and making my life much easier for a painful problem of how to cast time series data forward.

On addition i would to understand is how to make ll the NULL values come through as blank so I can automatically process them into a charting web service.
There seems to be multiple places as I have tried to zero them out but i would prefer blanks so the charting does not plot them at all.

I will go hunting for more tidbits you have uploaded to broaden my knowledge.

Thanks a lot
james.waugh28
james.waugh28
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
Points: 1 Visits: 1
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

mark.wojciechowicz@gmail.com
mark.wojciechowicz@gmail.com
SSC Rookie
SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)SSC Rookie (44 reputation)

Group: General Forum Members
Points: 44 Visits: 587
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

Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search