Results 1 to 4 of 4
  1. #1
    nlkehl is offline Novice
    Windows 8 Access 2013
    Join Date
    Jun 2014
    Posts
    7

    DCount to count unique values

    I am building a query to bring back 1 row for each ECT #. The annual amount needs to be a sum of all of the lines with the same ECT # and I want Access to count the number of unique equipment IDs on the lines with the same ECT #. I did a search in Access and it looks like I need to use the DCount function but I have not been able to set it up correctly. I continue to get a syntax error and I don't feel like the Access Help gives me much clarification.


    Here's a sample of the data and what I'm looking for it to return:

    ECT # Annual amount Equipment ID
    01-03 $100 1234
    01-05 $200 3456
    01-05 $150 1487
    01-03 $100 1234

    So, the query should return 2 lines as follows:

    ECT # Sum annual amt count equip ID
    01-03 $200 1
    01-05 $350 2

    I can successfully sum the annual amt but I have tried to use the Expression Builder to build a DCount function without success. I want it to count the # of unique 'equipment ID' per each ECT # from the table "VendorServiceContractExtract."
    Here is the expression that I've built that is not working:
    =DCount("[VendorServiceContractExtract]![Equipment Id]","[VendorServiceContractExtract]","criteria=n")

  2. #2
    lfpm062010 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Location
    US
    Posts
    415
    There is always more than one way to solve a problem. Let's called the table name "ETC".

    I choose to use 2 queries to do the work.

    1) First query select unique "ETC#", "Equipment ID" and sum the ".Annual amount"
    SELECT ETC.[ECT #], ETC.[Equipment ID], Sum(ETC.[Annual amount]) AS [SumOfAnnual amount]
    FROM ETC
    GROUP BY ETC.[ECT #], ETC.[Equipment ID];

    2) Then use the first query to get your count.
    SELECT SumETC.[ECT #], Sum(SumETC.[SumOfAnnual amount]) AS [SumOfSumOfAnnual amount], Count(SumETC.[Equipment ID]) AS [CountOfEquipment ID]
    FROM SumETC
    GROUP BY SumETC.[ECT #];

  3. #3
    nlkehl is offline Novice
    Windows 8 Access 2013
    Join Date
    Jun 2014
    Posts
    7
    I was hoping to avoid doing 2 queries and my help search in Access really made it sound like I could use this DCount function and nail it in 1 step. I may try that until someone else comes back with a 1 step solution. Thanks

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Perhaps something like:
    Code:
    SELECT Q.ECT, Count(Q.[Equipment ID]) AS [CountOfEquipment ID], Sum(Q.SumOfAnnualAmount) AS SumOfSumOfAnnualAmountFROM [SELECT VenServContExt.ECT, VenServContExt.[Equipment ID], Sum(VenServContExt.AnnualAmount) AS SumOfAnnualAmount FROM VenServContExt GROUP BY VenServContExt.ECT, VenServContExt.[Equipment ID]]. AS Q
    GROUP BY Q.ECT;
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

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

Similar Threads

  1. Replies: 5
    Last Post: 03-17-2014, 04:02 PM
  2. Replies: 3
    Last Post: 02-24-2014, 02:19 PM
  3. Count Unique Values in a Category
    By fionny in forum Queries
    Replies: 2
    Last Post: 06-28-2013, 02:28 AM
  4. Unique queries - Unique Count
    By bigfish in forum Queries
    Replies: 7
    Last Post: 03-14-2012, 01:28 PM
  5. Count of Unique Values
    By vsmk in forum Queries
    Replies: 2
    Last Post: 03-14-2010, 12:07 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