was wondering if somebody could shed some light on this topic for me.
I made a module that gives me the median value of some numbers (for some stupid reason MS Access doesn’t have a built-in median function). I found a module that gave me the basic outlines of the median function:
Function MedianMaker(tName As String, fldName As String) As Double
Dim MedianDB As Database
Dim ssMedian As Recordset
Dim RCount%, i%, x%, y%, OffSet%
Set MedianDB = CurrentDb()
Set ssMedian = MedianDB.OpenRecordset("SELECT [" & fldName & "] FROM [" & tName & "] WHERE [" & fldName & "] IS NOT NULL ORDER BY [" & fldName & "];")
ssMedian.MoveLast
RCount% = ssMedian.RecordCount
x% = RCount% Mod 2
If x% <> 0 Then
OffSet% = ((RCount% + 1) / 2) - 2
For i% = 0 To OffSet%
ssMedian.MovePrevious
Next i
MedianMaker = ssMedian(fldName$)
Else
OffSet% = (RCount% / 2) - 2
For i% = 0 To OffSet%
ssMedian.MovePrevious
Next i
x% = ssMedian(fldName$)
ssMedian.MovePrevious
y% = ssMedian(fldName$)
MedianMaker = (x% + y%) / 2
End If
ssMedian.Close
MedianDB.Close
End Function
This works all nice and well, but it doesn’t really give me what I need.
My data set looks something like this:
OBJECT CODE VALUES
111111 1
111111 2
111112 1
111112 4
111112 4
111112 5
111113 9
111113 2
111113 4
111114 4
111115…etc
In order for me to get just the median for object code 111111, would I have to do that seperately? Or is there a way where I can cross-tab all these suckers together and get the median for each individual object code?
I’ve been on this for awhile now and I am uber frustrated, hehe. Any help would be appreciated. Thanks =)