472,805 Members | 1,357 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 software developers and data experts.

Median in a report

I need to take the median from a field of records in a report. Can someone
shed the light how to do it.

Thanks,

Scott
Jan 29 '07 #1
3 4611


On Jan 29, 11:54 am, "Scott" <NoSpam-Scott...@GMail.comwrote:
I need to take the median from a field of records in a report. Can someone
shed the light how to do it.
Probably. Go to

http://groups.google.ca/group/comp.databases.ms-access

and then search for the word "median". Review the 115 results. Then,
if you still need help, follow-up with a more specific question.

Jan 29 '07 #2
Gord,

Thanks for your advice. I got below code and apply to my report without
success.

Function Median(tName As String, fldName As String) As Double
'Calculates the statistical median. To use this function type:
' =Median("DomainName", "FieldName")
'Domain name is the name of a query or table
'FieldName should be a numeric field.
Dim MedianDB As DAO.Database
Dim ssMedian As DAO.Recordset
Dim RCount As Long, i As Long, x As Double, y As Double, OffSet As Long
Set MedianDB = CurrentDb()
Set ssMedian = MedianDB.OpenRecordset( _
"SELECT [" & fldName & "]" & _
" FROM [" & tName & "]" & _
" WHERE [" & fldName & "] IS NOT NULL" & _
" ORDER BY [" & fldName & "]")
If ssMedian.RecordCount 0 Then
ssMedian.MoveLast
RCount = ssMedian.RecordCount
x = RCount Mod 2 'Determine if even or odd # of records
If x <0 Then 'Odd number of records
OffSet = (RCount - 1) \ 2
ssMedian.Move -OffSet
Median = ssMedian(fldName)
Else 'Even number of records
OffSet = (RCount / 2) - 1
ssMedian.Move -OffSet
x = ssMedian(fldName)
ssMedian.MovePrevious
y = ssMedian(fldName)
Median = (x + y) / 2
End If
End If 'records in recordset
ssMedian.Close
MedianDB.Close
End Function
The report is based on a query. I need to have the median in Category
Footer of the report and the field is a calculated field from the query. I
entered =Median("qryTELeadtime","QueuingTime") in controlsource of the
textbox created in the Category Footer. I got an error message saying that
"The expression you entered contains invalid syntax. You may have entered an
operand without an operator." Can someone point me out where the mistake
might be.

Thanks,

Scott

"Gord" <gd*@kingston.netwrote in message
news:11**********************@k78g2000cwa.googlegr oups.com...
>

On Jan 29, 11:54 am, "Scott" <NoSpam-Scott...@GMail.comwrote:
>I need to take the median from a field of records in a report. Can
someone
shed the light how to do it.

Probably. Go to

http://groups.google.ca/group/comp.databases.ms-access

and then search for the word "median". Review the 115 results. Then,
if you still need help, follow-up with a more specific question.

Jan 31 '07 #3
>I entered =Median("qryTELeadtime","QueuingTime") in controlsource of
>the textbox created in the Category Footer. I got an error message
saying that "The expression you entered contains invalid syntax. You
may have entered an operand without an operator." Can someone point
me out where the mistake might be.
Well,

=Median("DomainName", "FieldName")

works for me.

Check for typos.
On Jan 31, 1:12 pm, "Scott" <NoSpam-Scott...@GMail.comwrote:
Gord,

Thanks for your advice. I got below code and apply to my report without
success.

Function Median(tName As String, fldName As String) As Double
'Calculates the statistical median. To use this function type:
' =Median("DomainName", "FieldName")
'Domain name is the name of a query or table
'FieldName should be a numeric field.

Dim MedianDB As DAO.Database
Dim ssMedian As DAO.Recordset
Dim RCount As Long, i As Long, x As Double, y As Double, OffSet As Long

Set MedianDB = CurrentDb()
Set ssMedian = MedianDB.OpenRecordset( _
"SELECT [" & fldName & "]" & _
" FROM [" & tName & "]" & _
" WHERE [" & fldName & "] IS NOT NULL" & _
" ORDER BY [" & fldName & "]")

If ssMedian.RecordCount 0 Then
ssMedian.MoveLast

RCount = ssMedian.RecordCount
x = RCount Mod 2 'Determine if even or odd # of records

If x <0 Then 'Odd number of records
OffSet = (RCount - 1) \ 2
ssMedian.Move -OffSet
Median = ssMedian(fldName)

Else 'Even number of records
OffSet = (RCount / 2) - 1
ssMedian.Move -OffSet
x = ssMedian(fldName)
ssMedian.MovePrevious
y = ssMedian(fldName)
Median = (x + y) / 2
End If

End If 'records in recordset

ssMedian.Close
MedianDB.Close

End Function

The report is based on a query. I need to have the median in Category
Footer of the report and the field is a calculated field from the query. I
entered =Median("qryTELeadtime","QueuingTime") in controlsource of the
textbox created in the Category Footer. I got an error message saying that
"The expression you entered contains invalid syntax. You may have entered an
operand without an operator." Can someone point me out where the mistake
might be.

Thanks,

Scott

"Gord" <g...@kingston.netwrote in message

news:11**********************@k78g2000cwa.googlegr oups.com...
On Jan 29, 11:54 am, "Scott" <NoSpam-Scott...@GMail.comwrote:
I need to take the median from a field of records in a report. Can
someone
shed the light how to do it.
Probably. Go to
http://groups.google.ca/group/comp.databases.ms-access
and then search for the word "median". Review the 115 results. Then,
if you still need help, follow-up with a more specific question.

Feb 1 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Ross Contino | last post by:
Hello to all: I have been searching the web for examples on how to determine a median value in a mySQL table. I have reviewed the article at...
2
by: Hugo L. | last post by:
I really don't know how to calculate the median. Can anybody help me?
2
by: Bob | last post by:
I have been looking at the code for MedianFind(pDte As String) from the following thread from UtterAccess.com: "Finding Median average grouped by field" I have been able to get it to run using...
8
by: nick.vitone | last post by:
Hi, I'm somewhat of a novice at Access, and I have no experience programming whatsoever. I'm attempting to calculate the statistical median in a query. I need to "Group by" one column and find...
4
by: uspensky | last post by:
I have a table (cars) with 3 fields: VIN, Class, sell_price 101, sports, 10000 102, sports, 11000 103, luxury, 9000 104, sports, 11000 105, sports, 11000 106, luxury, 5000 107, sports, 11000
5
by: jonm4102 | last post by:
I'm trying to calculate the median of some numerical data. The data can only be found in a query (henceforth query 1) field I previously made, and I would prefer to calculate the median in a new...
3
by: Scldb | last post by:
I have a report(rptBuildRpt) that generates a report from a form(FrmBuildReports). On the report, I have a text box called txtMedian. I want to get the median of a column (Engine Price Est) in the...
7
by: Bhadan | last post by:
Hello, I have several jagged arrays which have been sorted. I'm trying to find the median of each array. Any tips appreciated. TIA. Bhads.
3
by: mehwishobaid | last post by:
i dont know wat is wrong with my code. when i compile. i get the error saying line 29: error: expression must have pointer-to-object type #include <iostream> using namespace std; #include...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.