Results 1 to 4 of 4
  1. #1
    MikeNewAccessUser is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    2

    Create a Field to Calculate Unique/Distinct Count

    Hi all! I'm an extremely new Microsoft Access user. I've created a new database that is linked to an Excel file. I have 2 tables of information similar to those listed below. In my query, I have a field for the unique descriptions and I want to add a field that will show the total store count of Unique or Distinct Descriptions. Based on the data below as an example, I would want the results of my query to be:



    Description Store Count
    Test Item A 5
    Test Item B 1

    Any thoughts on how this can be achieved? I appreciate and welcome any and all assistance. Thanks so much!
    TBLdata
    Store # Item # Description
    1 77400 Test Item A
    2 77400 Test Item A
    3 77400 Test Item A
    3 128756087 Test Item A
    4 77400 Test Item A
    4 128756087 Test Item A
    5 77400 Test Item A
    1 55897 Test Item B
    1 365476001 Test Item B
    AND

    TBLiteminfo
    Item # Description
    77400 Test Item A
    128756087 Test Item A
    55897 Test Item B
    365476001 Test Item B

  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
    52,929
    Do a query that returns Distinct values then use that query in another query to do aggregate count.

    Query1
    SELECT DISTINCT [Test Item], [Store #] FROM TBLData;

    Query2
    SELECT [Test Item], Count([Store #]) AS CountStore FROM Query1 GROUP BY [Test Item];

    As one nested query:
    SELECT [Test Item], Count([Store #]) AS CountStore FROM (SELECT DISTINCT [Test Item], [Store #] FROM TBLData) AS Query1 GROUP BY [Test Item];


    Advise not to use spaces and special characters/punctuation (underscore is exception) in naming convention.
    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
    NTC is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Posts
    2,392
    You need to perform what is called an Aggregate Query - it is a feature in Access you can look up. In your lay out above it is showing the A and B on a separate line - - if that is the case with your excel sheet then you have a problem and need to get those onto the same line as their data.

  4. #4
    MikeNewAccessUser is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    2

    Thumbs up

    Great. Thanks June7!

    Quote Originally Posted by June7 View Post
    Do a query that returns Distinct values then use that query in another query to do aggregate count.

    Query1
    SELECT DISTINCT [Test Item], [Store #] FROM TBLData;

    Query2
    SELECT [Test Item], Count([Store #]) AS CountStore FROM Query1 GROUP BY [Test Item];

    As one nested query:
    SELECT [Test Item], Count([Store #]) AS CountStore FROM (SELECT DISTINCT [Test Item], [Store #] FROM TBLData) AS Query1 GROUP BY [Test Item];


    Advise not to use spaces and special characters/punctuation (underscore is exception) in naming convention.

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

Similar Threads

  1. Replies: 3
    Last Post: 01-04-2013, 02:03 AM
  2. VB to calculate count of distinct values
    By gokul1242 in forum Programming
    Replies: 1
    Last Post: 10-03-2012, 01:38 PM
  3. Replies: 2
    Last Post: 06-05-2012, 12:33 PM
  4. Replies: 2
    Last Post: 02-04-2011, 08:27 AM
  5. Replies: 1
    Last Post: 12-10-2010, 11:03 AM

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