Results 1 to 2 of 2
  1. #1
    kestefon is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2013
    Posts
    108

    Count One Field & Sum Another?

    I have a dataset with "Date", "Product ID", and "Revenue" fields. I'd like to create a query that rolls the data up at the daily level and reports "Count of Product ID" (unique product IDs) and "Sum of Revenue". I'm having trouble figuring out the logic.

    Click image for larger version. 

Name:	DataSample.png 
Views:	9 
Size:	11.4 KB 
ID:	16001
    Last edited by kestefon; 03-31-2014 at 06:37 PM. Reason: Fixed screenshot/wording.

  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,632
    Are you showing this on a spreadsheet just for ease of posting? Really talking about an Access table?

    This could require multiple queries.

    SELECT DISTINCT [Date], ProductID FROM tablename;

    or

    SELECT [Date], ProductID FROM tablename GROUP BY [Date], ProductID;

    Then:

    SELECT [Date], Count(ProductID) AS CountProd FROM query1 GROUP BY [Date];

    SELECT [Date], Sum(Revenue) AS SumRev FROM tablename GROUP BY [Date];

    Now do a query that joins those two on the common [Date] field.


    The 2 product queries can be nested into one:

    SELECT [Date], Count(ProductID) AS CountProd FROM (SELECT [Date], ProductID FROM tablename GROUP BY [Date], ProductID) AS query1 GROUP BY [Date];
    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. Count what is in a field
    By Ruegen in forum Programming
    Replies: 8
    Last Post: 09-02-2013, 10:39 PM
  2. Replies: 4
    Last Post: 07-28-2013, 12:40 AM
  3. COUNT Group Count Records COUNT FUNCTION
    By PMCOFFEY in forum Access
    Replies: 9
    Last Post: 11-09-2012, 09:40 PM
  4. Count of Certain Values In a Field
    By tsn.s in forum Queries
    Replies: 4
    Last Post: 08-06-2012, 08:32 AM
  5. Replies: 2
    Last Post: 06-02-2012, 12:49 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