Results 1 to 6 of 6
  1. #1
    glmtd is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Jul 2012
    Posts
    5

    Calculating percentile with query

    Hello everyone. My data in one of the tables is stored in a long format, so 100 lines with numbers under each column. I would like to be able to calculate Percentile in ACCESS 2010 in a query. In Excel I use this formula =PERCENTILE(A1:A100, 0.16). Similarly, I would also like to also recreate this function =COUNTIF(A1:A100,"<=2")/100 in a query as well, to find the percentage of values that are below or equal to 2, or =COUNTIFS(A1:A100,">2",A1:A100,"<=64")/100 to calculate percentage between values larger than 2 and below 64.




    Thanks!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    I recommend building a report to do these calcs in.

    Review this thread http://www.mrexcel.com/forum/showthr...NTILE-function

    Here is a reference on using subqueries http://allenbrowne.com/subquery-01.html
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    glmtd is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Jul 2012
    Posts
    5
    Thank you for that June7.

    I've found a script that does work and calculates the percentile, but it needs some modifications for my data. My data is structured this way, but under each project I have 100 size numbers:

    Project Size
    Project1 1
    Project1 5
    Project1 3
    Project2 2
    Project2 4
    Project3 7

    I would like to be able to calculate percentile for each Project, and not for all of the data under size field name.

    Here is the script that calculates percentile for all of the data:

    Public Function XPercentile(FName As String, _
    TName As String, _
    X As Double) _
    As Double
    ' FName = Field name
    ' TName = Table name
    ' x = decimal percentile (0.68 for 68%)

    ' Return the minimum value for which x% of
    ' the values are lower or equal to it
    XPercentile = DMin(FName, TName, _
    "DCount(""*"", """ & TName & """, """ & FName & _
    "<="" & [" & FName & " ]) >= " & _
    X * DCount("*", TName))
    End Function

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    You are calling this function in a query or textbox ControlSource?

    The DCount will need criteria for the project ID and whatever is needed to exclude the undesired Size data..
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    glmtd is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Jul 2012
    Posts
    5
    I am calling this function in a guery. Could you provide me a with an example on how to specify the range of data in DCount, I am quite clueless in script. Thank You!

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Where does the X value come from? Is it a field in the query? Is Project the fieldname fed into the FName argument?

    Are you calling this function from other queries or code? Might be able to put the nested aggregate functions directly in the query.

    A report can group your data and do the percentile calcs.

    Domain aggregates can really slow query performance and, as you are finding, be cumbersome because any filter criteria used in the query must be replicated in the domain function.

    The function uses a DCount with a nested DCount. I expect both need the same filter criteria applied. My head is spinning.

    A report handles the dirty work for you. It allows display of detail records and summary calcs.

    Unless there is some compelling requirement to have it all accomplished within a query, I recommend a report.

    Might find this thread of interest https://www.accessforums.net/queries...ile-40273.html
    Last edited by June7; 12-20-2013 at 04:57 PM.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. how to do 75th percentile for a query field
    By vicki58 in forum Queries
    Replies: 3
    Last Post: 12-20-2013, 09:27 AM
  2. Replies: 14
    Last Post: 06-20-2012, 08:54 AM
  3. Replies: 1
    Last Post: 04-04-2012, 05:08 PM
  4. Calculating columns in crosstab query
    By GraemeG in forum Queries
    Replies: 11
    Last Post: 06-05-2011, 06:43 PM
  5. Calculating Sub Totals in a Query
    By cassidym in forum Queries
    Replies: 2
    Last Post: 06-09-2010, 01:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums