473,657 Members | 2,486 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Percentile Usage

12 New Member
ADezii,

i have been reading your solution to this percentile problem and believe you can help me.

I have a similar problem with creating a percentile in access 2007.

My table is called "TBL_DATA" and the field with all the values i would like to gain a percentile for is called "DAYS"

i want to develop a query which shows the following columns

- Min Days
- Max days
- Avg Days
- Percentile 95th
- Percentile 75th
- Percentile 50th
- Percentile 25th

i have created the first 3 columns in design view however am having problems creating the percentile calculations.

I would like access to look at all values under "DAYS" and bring back the percentile requested.

I am happyusing either a VBA script or a SQL statement as long as it gets the right answer.

Hope you can help, Thanking you in advance.
May 22 '09 #1
19 11163
ADezii
8,834 Recognized Expert Expert
@SachinPatel
  1. Copy and Paste the following 'Public' Function to a Standard Code Module:
    Expand|Select|Wrap|Line Numbers
    1. Public Function fCalculatePercentiles(sngPercentile As Single)
    2. 'Make sure to 1st set a Reference to the
    3. 'Microsoft Excel XX.X Object Library
    4. Dim sngNumbers() As Single
    5. Dim intNumberOfRecords As Integer
    6. Dim objExcel As Excel.Application
    7. Dim intCounter As Integer
    8. Dim MyDB As DAO.Database
    9. Dim rstPercentile As DAO.Recordset
    10.  
    11. Set MyDB = CurrentDb()
    12. Set rstPercentile = MyDB.OpenRecordset("TBL_DATA", dbOpenSnapshot)
    13. rstPercentile.MoveLast: rstPercentile.MoveFirst     'accurate Record Count
    14.  
    15. intNumberOfRecords = rstPercentile.RecordCount
    16.  
    17. 'Redimension the Array to proper values
    18. ReDim sngNumbers(1 To intNumberOfRecords)
    19.  
    20. Set objExcel = CreateObject("Excel.Application")
    21.  
    22. 'Populate the Array with values from the Recordset
    23. For intCounter = 1 To intNumberOfRecords
    24.   With rstPercentile
    25.     sngNumbers(intCounter) = ![Days]
    26.     .MoveNext
    27.   End With
    28. Next
    29.  
    30. 'Pass the Array to Excel's Percentile Function and Round the result to 2 Decimal Places
    31. fCalculatePercentiles = Round(objExcel.Application.Percentile(sngNumbers(), sngPercentile), 2)
    32.  
    33. 'Don't forget to clean up!!!
    34. rstPercentile.Close
    35. Set rstPercentile = Nothing
    36. objExcel.Quit
    37. Set objExcel = Nothing
    38. End Function
  2. Execute the following SQL Statement given your Table and Field Names:
    Expand|Select|Wrap|Line Numbers
    1. SELECT Min(TBL_DATA.Days) AS MinOfDays, Max(TBL_DATA.Days) AS MaxOfDays, Avg(TBL_DATA.Days) AS AvgOfDays, 
    2. fCalculatePercentiles(0.95) AS [95th Percentile], 
    3. fCalculatePercentiles(0.75) AS [75th Percentile], 
    4. fCalculatePercentiles(0.5) AS [50th Percentile], 
    5. fCalculatePercentiles(0.25) AS [25th Percentile]
    6. FROM TBL_DATA
    7. GROUP BY fCalculatePercentiles(0.25);
  3. Note that you are passing the actual Percentile Value to the fCalculatePerce ntiles() Function within the SQL Statement.
  4. Good Luck and Good Night!
May 23 '09 #2
SachinPatel
12 New Member
ADezil,

sorry to bother you buti have doneas you stated above however when i try run the query i am getting the error message as follows:

Undefined Function 'fCalculatePerc entiles' in expression

is there a certain way i shouldbe saving the VBA code to ensure the query can refer to it?
May 23 '09 #3
ADezii
8,834 Recognized Expert Expert
@SachinPatel
As previously stated in Post #30, Item 1, it must be defined as 'Public' in a Standard Code Module.
May 23 '09 #4
SachinPatel
12 New Member
Sorry mate - i believe i am defining the item as public, however as this is new to me maybe i am doing it wrong- can you possible tell me the correct way to define the function as public in a standard code module?
May 23 '09 #5
ADezii
8,834 Recognized Expert Expert
@SachinPatel
I'll do better than that. I'll be in work all day, but when I get home this evening I'll send you an Attachment indicating how, exactly, this is done. Be advised that this has only been tested on an insignificant amount of data, and may be incredibly slow on a large number of Records since you are using 3 Aggregate Functions, as well as several Calls to the same Public Function with different Parameters, within the Query. You may also experience some difficulty since you are essentially making the same Function Calls by passing different values (Percentiles). All the good stuff I'll leave to you - see you later. OK, was able to get it done here.
May 23 '09 #6
SachinPatel
12 New Member
thanks mate your a life saver - i will log on later (5 hours or so)

thanks again your a star!
May 23 '09 #7
ADezii
8,834 Recognized Expert Expert
@SachinPatel
Just in case you didn't notice the previous Post, I was able to create the Attachment in work. Good Luck.
May 23 '09 #8
NeoPa
32,568 Recognized Expert Moderator MVP
I have split this away from Percentile calculation in Access as it is a different question.

I know you're very new so we'll let it slide this time, but posting your question in an existing thread is hijacking, and is not allowed on this site.

I don't, for a moment, want to stop you asking questions, simply guiding you do do it the proper way in future.

Welcome to Bytes!

NB. Post #6 has the attachment ADezii promised you. Don't overlook it simply because it's not the latest post ;)
May 23 '09 #9
SachinPatel
12 New Member
hey ADezii,

just seeing if you had chance to send over how to make a vba function public and refer toit on the sql you created without getting an error message.

Thanks
May 23 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
460
by: tomvr | last post by:
Hello I have noticed some 'weird' memory usage in a vb.net windows app The situation is as follows I have an app (heavy on images) with 2 forms (actually there are more forms and on starting the app I load some things into memory for global use of the app but I'll use only 2 starting forms to explain the situation) situation 1 start app with form 1 (72mb memory usage), show form 2 and hide form 1 (89 mb memory usage
3
4135
by: Ian Taite | last post by:
Hello, I'm exploring why one of my C# .NET apps has "high" memory usage, and whether I can reduce the memory usage. I have an app that wakes up and processes text files into a database periodically. What happens, is that the app reads the contents of a text file line by line into an ArrayList. Each element of the ArrayList is a string representing a record from the file. The ArrayList is then processed, and the arraylist goes out of...
2
3279
by: jd142 | last post by:
Normally when people ask about getting the Nth percentile from a group, the response is to write a couple of VBA modules. But it seems to me there's a simpler way that just uses 2 queries. You might even be able to get it down to one query if you nest them. Here's how I get the 25th percentile number from a table, where mynumber is the field that has the value and mytable is the table name: top_25_query: select top 25 percent...
3
13468
by: Dave Veeneman | last post by:
I'm looking from an algorithm that will do a statistics calculation for me-- it's the first time 'Numerical Recipies in C' has failed me! A normal distribution table tells me the probability (by percentile) of an item, given something called a z-score. If I have a z-score, I can look up the probability in a distribution table. There are plenty of algorithms around to do that calculation, but I need to do a reverse lookup. I am given a...
1
14297
by: Joe | last post by:
Has anyone written a percentile rank algorithm that they can share or know of a good resource that defines the algorithm. I'm starting a project that involves percentile ranks, logistic and linear regression. If not c# any language or pseudo code would be very useful. Thank you. Joe -- Sent via .NET Newsgroups http://www.dotnetnewsgroups.com
10
2087
by: rdemyan via AccessMonster.com | last post by:
My app contains utility meter usage. One of the things we have to deal with is when a usage is clearly incorrect. Perhaps someone wrote the meter reading down incorrectly or made a factor of 10 error when entering the reading, etc. At other times the usage is zero or somehow was entered as a negative number. So I'm thinking about adding functionality to search for such anomalies. For instance, show months where the meter reading is...
3
9395
by: Sirisha | last post by:
I am using the following code to get the CPU usage PerformanceCounter myCounter; myCounter = new PerformanceCounter(); myCounter.CategoryName = "Processor"; myCounter.CounterName = "% Processor Time"; myCounter.InstanceName = "_Total"; for(int i=0; i < 20; i++)
28
19671
by: riaane | last post by:
Hey clever people, Excel has the =PERCENTILE function. This calulates a percentile value from an array of values. Is there any equivalent in Access?
5
4507
by: artemetis | last post by:
Hello! It's me again. tblEmp -->empUid - self explanatory -->empPerf - ranking from 0 - 100 I'm interested in creating a query that displays the top x% (eg, 20%) of employee performance, based on empPerf. Qry operator will be prompted for value of X%. I'm not too familiar with stats, but searched through the site and found l was only able to find something regarding Excel.
0
8392
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8305
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8823
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8603
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1944
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1604
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.