Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 235
  • Last Modified:

Use public function in MS Access query

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
mugua
Asked:
mugua
1 Solution
 
jadedataMS Access Systems CreatorCommented:
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
 
bonjour-autCommented:
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
 
joekendallCommented:
Did the above solution(s) fix your problem?
0
 
stevbeCommented:
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

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now