Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Database Design / December 2003

Tip: Looking for answers? Try searching our database.

Figuring Median

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Brian Wagoner - 30 Dec 2003 18:01 GMT
How do you figure median in access 2003.  I am trying to
report on average and median times for things like
emergency room to CT, CT done to CT report.  Help my
bosses eyes are turning red. Thanks Brian
Tim Ferguson - 30 Dec 2003 19:23 GMT
> How do you figure median in access 2003.

Open a snapshot recordset, sorted on the field you are interested in.

Get the .RecordCount value:
 if it's an even number
   get the n/2 and n/2 +1 'th records and use the mean value

 else if it's an odd number
   get the (n+1)/2 'th value and use that

 else
   there are no records in the recordset

 end if

There is example code around on the web -- I think Steve Lebans has some on
<http://www.lebans.com>

Hope that helps

Tim F
Sam - 30 Dec 2003 22:44 GMT
Here's a function I use...

It works just like the included domain functions...

Public Function DMedian(Expr As String, Domain As String, Optional Criteria
As String) As Double
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim Temp As Double
Dim OrderedSQL As String

'construct SQL
OrderedSQL = "SELECT " & Expr
OrderedSQL = OrderedSQL & " FROM " & Domain
If Criteria <> "" Then
   OrderedSQL = OrderedSQL & " WHERE " & Criteria
End If
OrderedSQL = OrderedSQL & " ORDER BY " & Expr & ";"

Set db = CurrentDb
Set rs = db.OpenRecordset(OrderedSQL)

rs.MoveLast
NumRecords = rs.RecordCount
rs.MoveFirst
rs.Move Int(NumRecords / 2)
Temp = rs.Fields(Expr)

If NumRecords / 2 = Int(NumRecords / 2) Then

   'there is an even number of records
   rs.MovePrevious
   Temp = Temp + rs.Fields(Expr)
   DMedian = Temp / 2

Else

   'there is an odd number of records
   DMedian = Temp

End If

rs.Close
db.Close

End Function

HTH
Sam
> How do you figure median in access 2003.  I am trying to
> report on average and median times for things like
> emergency room to CT, CT done to CT report.  Help my
> bosses eyes are turning red. Thanks Brian
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.