Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Grouping Problem

Posted on 2004-09-21
8
Medium Priority
?
318 Views
Last Modified: 2008-02-01
Hello Experts,

Today just isn't my day!  I am trying to figure out how I can find the deviation from the linear regression through the use of custom made functions.

So far i have this...

___________________________________________________________________________
Option Compare Database

Function LinRegSlope(n, x, y, xy, xx)

'n = Count of items
'x = Sum of the X Axis
'y = Sum of the Y Axis
'xy = Sum of the X Axis * the Y Axis  SUM(x*y)
'xx = x^2

LinRegSlope = ((n * (xy)) - ((x) * (y))) / ((n * (xx)) - ((x) * (x)))     'The slope of the line

End Function

Function LinRegYInt(n, x, y, xy, xx)


'n = Count of items
'x = Sum of the X Axis
'y = Sum of the Y Axis
'xy = Sum of the X Axis * the Y Axis  SUM(x*y)
'xx = x^2


Dim m As Double ' Slope

m = ((n * (xy)) - ((x) * (y))) / ((n * (xx)) - ((x) * (x)))     'm = The slope of the line

LinRegYInt = (y - (m * x)) / n

End Function
________________________________________________________________________

This is working fine but my problem is the grouping.  Is there a way i can use the SUM and at the same time find the deviation from an indivual record?

Thanks!
0
Comment
Question by:Navicerts
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
8 Comments
 
LVL 27

Assisted Solution

by:jjafferr
jjafferr earned 400 total points
ID: 12116628
Hi Navicerts,


you can use the dsum with a where condition
0
 
LVL 16

Accepted Solution

by:
Nestorio earned 1600 total points
ID: 12117009
You can use a sum this way in a query:

Select fld1, (select sum(amount1) from table1) as SumAmount
From table1
0
 
LVL 16

Expert Comment

by:Nestorio
ID: 12117115
Example using a function:

Select LinRegSlope((select count(*) from table), (select sum(x) from table), (select sum(y) from table), (select sum(x*y) from table), (select sum(x*x) from table)) as m
From table

0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
LVL 16

Expert Comment

by:Nestorio
ID: 12119190
Try this:

SELECT x, y, y - (q.m*x+ q.b) AS Deviation
FROM tablexy, [select
        count(*) as n,
        sum(x) as sx,
        sum(y) as sy,
        sum(x*x) as sxx,
        sum(x*y) as sxy,
        ((n * (sxy)) - ((sx) * (sy))) / ((n * (sxx)) - ((sx) * (sx)))  as m,
        (sy - (m * sx)) / n as b  from tablexy]. AS q;

where "x" and "y" are the fields x and y of the table "tablexy"
0
 
LVL 7

Author Comment

by:Navicerts
ID: 12122151
I stopped working on it about an hour after i made the post yesterday, sorry for the delay :)  I'll test this out today and let you guys know how it works out, thank you for all the suggestions!
0
 
LVL 16

Expert Comment

by:Nestorio
ID: 12122707
Hi Navicerts,

I've tested  the last solution I posted and it worked OK. Just one query and no need to use functions.

Regards
0
 
LVL 16

Expert Comment

by:Nestorio
ID: 12160502
Hi Navicerts,

Any updates on this?
0
 
LVL 7

Author Comment

by:Navicerts
ID: 12160879
oops! forgot to come back to this one, i tried out both options and they work.  I am going to go with making the functions because my end users like to do thier own sql statements and use access so i figure ill give them a function they can use.  Unfortunatly i have been sidetracked before i could finish the project (not a surprise here).  But thank you for the soultions!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question