PC Review


Reply
Thread Tools Rate Thread

Calculating Quartiles

 
 
Mark
Guest
Posts: n/a
 
      10th May 2004
Hello,

Is there a way of calculating quartiles (value of a field
at each 25% of observations when sorted into ascending
order) in a query expression?

Excel can do this with the "Quartile" function but Access
does not seem to support this.

At the moment I am hard coding the values of the quartiles
into my query expression like this:

Quartile: IIf([tblStore].[SumOfValue]<=438771,"Low",IIf
([tblStore].[SumOfValue]<=1645333,"Medium",IIf([tblStore].
[SumOfValue]<=4840280,"High",IIf([tblStore].[SumOfValue]
<=23730230,"Very High","Error"))))

The 4 numbers in this expression are the values of the
quartiles as calculated in Excel, but I need a more
dynamic way of doing it so that if the underlying data
changes so will my quartile values.

Thank you for any help in advance.

Mark
 
Reply With Quote
 
 
 
 
Michel Walsh
Guest
Posts: n/a
 
      11th May 2004
Hi,




SELECT a.value, COUNT(*) As rank
FROM myTable As a INNER JOIN myTable As b
ON a.value <= b.value
GROUP BY a.value

would rank the values (First, second, 3, 4, ....., N ). If you save that
query, say under the name Q1, then



SELECT INT( (q1.rank-1)/4 )+1 As Quartile,
MIN(q1.value) As lowestValueInQuartile,
MAX(q1.value) As highestValueInQuartile
FROM q1
GROUP BY INT( (q1.rank-1)/4 )+1


that would return the minimum and maximum value for each quartile



Hoping it may help,
Vanderghast, Access MVP




"Mark" <(E-Mail Removed)> wrote in message
news:aad601c4366f$8ee04a30$(E-Mail Removed)...
> Hello,
>
> Is there a way of calculating quartiles (value of a field
> at each 25% of observations when sorted into ascending
> order) in a query expression?
>
> Excel can do this with the "Quartile" function but Access
> does not seem to support this.
>
> At the moment I am hard coding the values of the quartiles
> into my query expression like this:
>
> Quartile: IIf([tblStore].[SumOfValue]<=438771,"Low",IIf
> ([tblStore].[SumOfValue]<=1645333,"Medium",IIf([tblStore].
> [SumOfValue]<=4840280,"High",IIf([tblStore].[SumOfValue]
> <=23730230,"Very High","Error"))))
>
> The 4 numbers in this expression are the values of the
> quartiles as calculated in Excel, but I need a more
> dynamic way of doing it so that if the underlying data
> changes so will my quartile values.
>
> Thank you for any help in advance.
>
> Mark



 
Reply With Quote
 
Michel Walsh
Guest
Posts: n/a
 
      11th May 2004
Hi,


replace

INT((q1.rank-1)/4)+1

with


INT(4*(q1.rank-1)/(SELECT MAX(q1.rank)))+1



at both two occurrences.


The idea is to produce a value giving the quartile (1, 2, 3 or 4) the
rank makes the values to belong to.



Hoping it may help,
Vanderghast, Access MVP


"Michel Walsh" <vanderghast@VirusAreFunnierThanSpam> wrote in message
news:(E-Mail Removed)...
> Hi,
>
>
>
>
> SELECT a.value, COUNT(*) As rank
> FROM myTable As a INNER JOIN myTable As b
> ON a.value <= b.value
> GROUP BY a.value
>
> would rank the values (First, second, 3, 4, ....., N ). If you save that
> query, say under the name Q1, then
>
>
>
> SELECT INT( (q1.rank-1)/4 )+1 As Quartile,
> MIN(q1.value) As lowestValueInQuartile,
> MAX(q1.value) As highestValueInQuartile
> FROM q1
> GROUP BY INT( (q1.rank-1)/4 )+1
>
>
> that would return the minimum and maximum value for each quartile
>
>
>
> Hoping it may help,
> Vanderghast, Access MVP
>
>
>
>
> "Mark" <(E-Mail Removed)> wrote in message
> news:aad601c4366f$8ee04a30$(E-Mail Removed)...
> > Hello,
> >
> > Is there a way of calculating quartiles (value of a field
> > at each 25% of observations when sorted into ascending
> > order) in a query expression?
> >
> > Excel can do this with the "Quartile" function but Access
> > does not seem to support this.
> >
> > At the moment I am hard coding the values of the quartiles
> > into my query expression like this:
> >
> > Quartile: IIf([tblStore].[SumOfValue]<=438771,"Low",IIf
> > ([tblStore].[SumOfValue]<=1645333,"Medium",IIf([tblStore].
> > [SumOfValue]<=4840280,"High",IIf([tblStore].[SumOfValue]
> > <=23730230,"Very High","Error"))))
> >
> > The 4 numbers in this expression are the values of the
> > quartiles as calculated in Excel, but I need a more
> > dynamic way of doing it so that if the underlying data
> > changes so will my quartile values.
> >
> > Thank you for any help in advance.
> >
> > Mark

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Quartiles Mike Dobony Microsoft Excel Worksheet Functions 1 2nd Feb 2009 02:55 PM
QUARTILES in SQL/QUERY BlueWolverine Microsoft Access Queries 3 31st Oct 2008 01:57 PM
Group by for quartiles =?Utf-8?B?UEpGcnk=?= Microsoft Access Queries 1 15th Oct 2007 03:29 PM
Calculating quartiles in a query Paras Shah Microsoft Access 7 5th May 2004 04:00 PM
Calculating quartiles in a query Paras Shah Microsoft Access Queries 7 5th May 2004 04:00 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:53 AM.