Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Use public function in MS Access query

Posted on 2003-10-24
5
Medium Priority
?
233 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
[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
  • Learn & ask questions
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 760 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

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.
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

660 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