?
Solved

PercentRanking in Access2002

Posted on 2009-02-20
5
Medium Priority
?
220 Views
Last Modified: 2013-11-27
Is there a way to to calcualte PercentRank in Access? Creating productivity report for team and need to rank preformace daily ... have tried and always fails.... Help Please!
Public Function myPercentRank(t As String, f As String, d As Double) As Double
 
    Dim rs As DAO.Recordset
    Dim v As Variant
    
    Set rs = CurrentDb.OpenRecordset("SELECT " & f & " FROM " & t & ";")
    v = rs.GetRows
    
    myPercentRank = Excel.WorksheetFunction.PercentRank(v, d)
    rs.Close
    Set rs = Nothing
End Function
 
SELECT RankRepo.Name, RankRepo.AssgnHr, myPercentRank("RankRepo","AssgnHr",[AssgnHr]) AS Expr1
FROM RankRepo;

Open in new window

0
Comment
Question by:SusanSSS
  • 3
  • 2
5 Comments
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 23693136
Hello SusanSSS,

Please explain what you are trying to do.

Regards,

Patrick
0
 

Author Comment

by:SusanSSS
ID: 23694873
Hello!

PERCENTRANK is a function in Excel, I need to find away to do it in Access

Calls      Calls PR
14.13      71.42%
12.30      50.00%
12.08      42.85%
15.52      78.57%
8.13      0.00%
11.33      28.57%
29.43      100.00%
11.12      21.42%
9.88      7.14%
11.45      35.71%
13.33      64.28%
11.11      14.28%
18.12      85.71%
25.17      92.85%
12.59      57.14%

In excel    =PERCENTRANK($S$2:$S$16,S2,4)

0
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 23695242
This seems to do it:



Public Function myPercentRank(t As String, f As String, d As Double) As Double

    Dim rsBelow As DAO.Recordset
    Dim rsCount As DAO.Recordset
    Dim arr() As Double
   
    Set rsBelow = CurrentDb.OpenRecordset("SELECT Count(*) AS Cnt FROM [" & t & "] " & _
        "WHERE [" & f & "] < " & d)
    Set rsCount = CurrentDb.OpenRecordset("SELECT Count(*) - 1 AS Cnt FROM [" & t & "]")
   
    myPercentRank = rsBelow!cnt / IIf(rsCount!cnt > 0, rsCount!cnt, 1)

    rsCount.Close
    rsBelow.Close
    Set rsCount = Nothing
    Set rsBelow = Nothing

End Function
0
 
LVL 93

Accepted Solution

by:
Patrick Matthews earned 1000 total points
ID: 23695342
You really do not even need a UDF...



SELECT [Name], AssgnHr, DCount("*", "RankRepo", "[AssgnHr] < " & [AssgnHr]) / IIf(DCount("*", "RankRepo") > 1, DCount("*", "RankRepo") - 1, 1) AS PercRank
FROM RankRepo;
0
 

Author Closing Comment

by:SusanSSS
ID: 31549454
Thank you!! This worked... I have tried several way and this was fast and easy.
Susan
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
MSSQL DB-maintenance also needs implementation of multiple activities. However, unprecedented errors can hamper the database management. In that case, deploying Stellar SQL Database Toolkit ensures fast and accurate database and backup repair as wel…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
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 …

809 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