Results 1 to 5 of 5
  1. #1
    BRZ-Ryan is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2013
    Posts
    187

    Query to exclude outliers

    I'm creating a query that is getting the max and min values from a table.

    I have an issue where there are occasionally some outliers at the top or bottom values that are throwing off what we expect as a result. I want to create a query that uses comboboxes with a values from 1-20 that when selected, with exclude the top and bottom N rows.

    Example data:
    22


    535
    567
    664
    701
    3200
    3434

    So in this case, I do not want 22, 3200, 3434 so I'd like to select 1 from the bottom combo to exclude that 1 bottom record, and select 2 from top combo to exlude 3200 and 3434.

    I am currently using 3 queries to achieve this but results are not correct. Is this the correct approach or is there a better way.
    Code:
    SELECT Max(Seconds) AS MX, Min(Seconds) AS MN
    FROM (SELECT TOP 90 Seconds FROM 
    (SELECT TOP 95 Seconds 
    FROM 
    (
    SELECT Seconds 
    FROM tblTestRanges) AS AllSec 
    ORDER BY Seconds) AS ASCSec 
    ORDER BY Seconds DESC) AS DESCSec;

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    I don't know your background or the level of detail you need. You might want to look at standard deviation and the related access functions It may give you a better and more consistent means of identifying or ignoring outliers.

  3. #3
    BRZ-Ryan is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2013
    Posts
    187
    Whatever you think is best, do you have any recommendations on how to pull this off with the data provided?

    I'm a novice at SQL, experienced in VB. I've never used the StDev() function.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    What is the data you are dealing with -- in plain English? I don't have any specific info --outliers are often subjective.
    What is not correct with
    I am currently using 3 queries to achieve this but results are not correct.

  5. #5
    BRZ-Ryan is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2013
    Posts
    187
    When I select to exclude the top highest, my numbers are drastically reduced.

    I just did a Count query on the above results and I did one on the full data set (inner most in the nest)

    Dataset = 496 records
    Query using 99/99 as top/bottom = 99 records.. This should be 494.

    Edit: I think I figured this out!

    Here's what I used. The inner query I am subtracting the 1 record I do not want. On the outer query I take the resulting value of that (99) and subtract 1 since I am only left with 99, this is why the outside takes the top 98.
    Code:
    SELECT Min(Seconds) As MinSec, Max(Seconds) As MaxSec
    FROM (
    SELECT TOP 98 tblTime.Seconds
    FROM (
    SELECT TOP 99 tblTime.Seconds
    FROM (
    SELECT tblTime.Seconds
    FROM tblTime, tblEmp
    WHERE tblTime.EmpID=tblEmp.ID AND tblEmp.EmpType=1
    ORDER BY tblTime.Seconds) AS [RangeAll]
    ORDER BY tblTime.Seconds ASC) AS [RangeDESC]
    ORDER BY tblTime.Seconds DESC) As [RangeASC];

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

Similar Threads

  1. Exclude IDs in grouped query
    By Ruegen in forum Queries
    Replies: 2
    Last Post: 09-02-2014, 09:27 PM
  2. Query Criteria to exclude data
    By vnms2001 in forum Queries
    Replies: 2
    Last Post: 08-07-2014, 12:19 PM
  3. Exclude TOP N records from query
    By gemadan96 in forum Queries
    Replies: 4
    Last Post: 06-15-2014, 10:11 AM
  4. exclude field in query
    By chrisy in forum Queries
    Replies: 2
    Last Post: 10-28-2011, 09:53 AM
  5. Replies: 4
    Last Post: 10-25-2011, 10:07 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