Solved

Use public function in MS Access query

Posted on 2003-10-24
5
226 Views
Last Modified: 2011-09-20
I am trying to calculate percentile using a MS Access query.
and I am trying to use a Access query that calls a function.

For example, I have a table and with field A, B, and C.  I need to first group the table by A and B, then within each group I need to calculate percentile for C.

I understand I can write a function using VBA but then the function works only for the whole column of C. The function would need input of table name, field name, and percentile.  Can anybody please show me how to apply the function for each group (by A and B) instead of just the whole field?

Please help.  Thanks a lot!
0
Comment
Question by:mugua
5 Comments
 
LVL 32

Expert Comment

by:jadedata
ID: 9617432
Hey mugua!

 a percentile require something to compare against:  x/y = z%
 With the total in Group A/B being x,..
 Where will the y value come from?

regards
Jack
0
 
LVL 18

Accepted Solution

by:
bonjour-aut earned 190 total points
ID: 9617723
if you want to use in a query, you will calculate each record

something like      DoPerc(A,B,C)  - you have this value at hand in your query

Public Function DoPerc( a_val As Double, b_val As Double c_val As Double) As Double
Dim sqlstr As String
Dim rs As Recordset
sqlstr = "SELECT >some Agregatfunction with A.basetab, B.basetab< FROM basetab GROUP BY A.basetab, B.basetab;"

now do your calculation with rs.Fields(0),rs.Fields(1) & c_val

DoPerc = ................
End Function

Depending on the amount of data, it would be less calculating doing a straight forward double loop, maybe to a temp table ?

regards, franz
0
 
LVL 11

Expert Comment

by:joekendall
ID: 9647050
Did the above solution(s) fix your problem?
0
 
LVL 39

Expert Comment

by:stevbe
ID: 9991273
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: bonjour-aut {http:#9617723}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

stevbe
EE Cleanup Volunteer
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

707 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now