### Tags: access, base, calculate, calculation, database, history, line, microsoft, monthly, mysql, oracle, sales, slope, sql, trend

# Calculate slope of a data set or trend line

On Database » Microsoft Access

3,909 words with 4 Comments; publish: Wed, 02 Jan 2008 20:01:00 GMT; (25046.88, « »)

Hello everyone,

I hope someone is out here who can help me with a simple calculation...

I have a sales data base in access with monthly sales history by

product. to make future predictions I need the slope (representing

growth) of monthly sales.

the data is setup in a crosstab with the months in different collums,

say column 1 to 12 for last year. I want to calculate the slope for

every row (on the same query or another if needed)

Does anyone have an idea how to calculate the slope of the trendline

for those values? In excel I can just use =slope(known y's, known x's).

the slope i need is from the trendline in common statistics (I believe

it is calcuated by minimizing the sum of the squared deviation - OLS)

I cannot use an ordinary excel export (too many lines).

Anyone an idea how to work around that?

Help is much appreciated,

Thanks

Kai

*http://ms-access.todaysummary.com/q_ms-access-database_26439.html*

All Comments

Leave a comment...

- 4 Comments
- In your case, if the months are m=1,2...12 and, for each record
you have the 12 observations: y(1)...y(m)...y(12),

the slope is given by:

[ sum for m = 1 to 12 of (m-6.5) * y(m) ] / 143

PS

In the particular case when y(m) = b * m for each m,

you should get slope = b where b is any real

-tom

kux ha scritto:

> Hello everyone,

> I hope someone is out here who can help me with a simple calculation...

>

> I have a sales data base in access with monthly sales history by

> product. to make future predictions I need the slope (representing

> growth) of monthly sales.

> the data is setup in a crosstab with the months in different collums,

> say column 1 to 12 for last year. I want to calculate the slope for

> every row (on the same query or another if needed)

> Does anyone have an idea how to calculate the slope of the trendline

> for those values? In excel I can just use =slope(known y's, known x's).

> the slope i need is from the trendline in common statistics (I believe

> it is calcuated by minimizing the sum of the squared deviation - OLS)

> I cannot use an ordinary excel export (too many lines).

> Anyone an idea how to work around that?

> Help is much appreciated,

> Thanks

> Kai

#1; Wed, 02 Jan 2008 20:02:00 GMT

- In your case, if the months are m=1,2...12 and, for each record
- Hello Tom,
thanks a lot for that formula. It works great with the data i checked.

but how do you get to 143?

I need to do similar calculations with other time frames as well (24,

36 and 48 months). I could always try it out but I would rahter enter a

formula in case someone changes the lenght of the period later...

THanks

Kai

#2; Wed, 02 Jan 2008 20:03:00 GMT

- Hello Tom,
- Hi Kai, sorry for ignoring your second question, I missed it.
I hope I got it right (I have done some quick hand computation)...

In a more general case, where one has H consecutive equispaced time

occasions

y(1)...y(m)...y(H), the slope should be:

[ sum for m = 1 to H of (m - (H+1)/2) * y(m) ] / D

where: D = H * (H ^ 2 - 1) / 12

or, if you prefer: D = H * (H + 1) * (H - 1) / 12

-tommaso

PS

let me know if it works fine

Kux ha scritto:

> Hello Tom,

> thanks a lot for that formula. It works great with the data i checked.

> but how do you get to 143?

> I need to do similar calculations with other time frames as well (24,

> 36 and 48 months). I could always try it out but I would rahter enter a

> formula in case someone changes the lenght of the period later...

> THanks

> Kai

#3; Wed, 02 Jan 2008 20:05:00 GMT

- Hi Kai, sorry for ignoring your second question, I missed it.
- Hey Tom,
to be honest, I dont understand why the formula looks like it does. but

it WORKS!

...and in the meantime I found that it is also the sum for m = 1 to 12

of (m-6.5)^2. (you can replace 12 with H and 6.5 with (H+1)/2)

That holds true at least for the values I checked. I would be surprised

if that is a coincidence but could not say why it works.

thank you so much. That completely solved my problem.

kai

#4; Wed, 02 Jan 2008 20:05:00 GMT

- Hey Tom,