Results 1 to 4 of 4
  1. #1
    JKnightly is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2015
    Posts
    4

    Top 25 records per group


    I have a query and a table that are linked and I want to show the top 25 records for each group, I have found a few different forum posts and Microsoft articles about this exact question but cannot seem to get anything working. Here are some specific details about my query and table. The query sums all of the sales for the year by customer number.

    Query: [Sales by Customer No for Current Year]
    Fields: [CustomerNo], [Sales]

    Table: [AR_Customer]
    Fields: [CustomerNo], [UDF_CC_DROPDOWN]

    I am trying to show the top 25 customers based on the sales volume grouped on customer class (the UDF_CC_DROPDOWN field).

    I am probably missing something basic, any help would be greatly appreciated.

    - Jonathan
    Access 2010

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,642
    So what specifically have you found and tried? Have you seen http://allenbrowne.com/subquery-01.html#TopN

    The query does not have customer class grouping.

    You want the top 25 customers for each class? Or just the top 25 volume records?
    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
    JKnightly is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2015
    Posts
    4
    I want to see the 25 customers with the highest sales volume for each customer class. I have looked at http://allenbrowne.com/subquery-01.html#TopN and could not seem to get the syntax or something right. And I looked at a few different Microsoft articles which referenced much earlier versions of access but I wasn't able to get the suggestions mentioned there working either.

    Maybe you can tell me what I am doing wrong, here is the SQL:

    SELECT AR_Customer.UDF_CC_DROPDOWN, [Sales by Customer No for Current Year].Sales, AR_Customer.CustomerNo
    FROM [Sales by Customer No for Current Year] INNER JOIN AR_Customer ON [Sales by Customer No for Current Year].CustomerNo = AR_Customer.CustomerNo
    WHERE ((([Sales by Customer No for Current Year].Sales) In (Select TOP 25 Sales
    FROM [Sales by Customer No for Current Year] AS Dupe
    WHERE Dupe.CustomerNo = AR_Customer.CustomerNo
    ORDER BY AR_Customer.UDF_CC_DROPDOWN DESC, Dupe.Sales, Dupe.CustomerNO)))
    ORDER BY AR_Customer.UDF_CC_DROPDOWN DESC;

    The query just sits there when I run it. It shows running query in the bottom right hand corner but nothing happens, no error messages or results.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,642
    Provide sample raw data. Can be attached file or build a table in post. An example of desired output would be nice.

    If you want to return top 25 customers for each class, seems to me the [Sales by Customer No for Current Year] query will have to group by class as well as customer.
    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. TOP (N) Records in a Group
    By wcrimi in forum Queries
    Replies: 42
    Last Post: 01-03-2015, 11:54 AM
  2. Group and Sum Records in a Query
    By majoh60 in forum Queries
    Replies: 7
    Last Post: 06-15-2013, 10:36 PM
  3. Assigning records to a group.
    By gemadan96 in forum Access
    Replies: 12
    Last Post: 10-30-2012, 03:43 PM
  4. Print records by group
    By lizzywu in forum Reports
    Replies: 1
    Last Post: 10-20-2011, 10:31 AM
  5. Trying to sum a group of records not working
    By shelbsassy in forum Reports
    Replies: 0
    Last Post: 04-10-2011, 07:52 PM

Tags for this Thread

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