Solved

# Use public function in MS Access query

Posted on 2003-10-24
232 Views
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?

0
Question by:mugua
[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

LVL 32

Expert Comment

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

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

ID: 9647050
Did the above solution(s) fix your problem?
0

LVL 39

Expert Comment

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}

stevbe
EE Cleanup Volunteer
0

## Featured Post

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
###### Suggested Courses
Course of the Month9 days, 7 hours left to enroll