Results 1 to 6 of 6
  1. #1
    falahsalih is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    May 2014
    Posts
    38

    Dsun function to sum the sales of each customer

    Hi everybody.


    Can Dsum function sums the sales of each customer. For example, let say we have the following query
    Code:
    QueryCustomerSales 
    Customer Name 
    Order ID
    Item 
    Amount 
    Price
    So, can i get output something like :

    Code:
    John    200.540 $
    Mark    300.350 $
    I tried the following code "

    Code:
    Dsum ("[Amount] * [Price]", "QueryCustomerSales", "[Customer Name]= [Customer Name]")
    However, it returns the sales of all customers (all together ):

    Code:
    John    500.890 $
    Mark    500.890 $

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    don't do this with a dsum function. Use an aggregate query


    SELECT [Customer Name], Sum([Amount] * [Price]) as TotalSpent FROM <SALESTABLENAME> GROUP BY [Customer Name]

  3. #3
    falahsalih is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    May 2014
    Posts
    38
    Quote Originally Posted by rpeare View Post
    don't do this with a dsum function. Use an aggregate query


    SELECT [Customer Name], Sum([Amount] * [Price]) as TotalSpent FROM <SALESTABLENAME> GROUP BY [Customer Name]
    Can I involve another sum function (example: sum of payments for the same customer ) in the sql code ?

  4. #4
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    yes you can, just add the field you want to sum and select SUM in the TOTALS line of the query design window.

  5. #5
    falahsalih is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    May 2014
    Posts
    38
    Quote Originally Posted by rpeare View Post
    yes you can, just add the field you want to sum and select SUM in the TOTALS line of the query design window.
    I got error "circular reference caused by QueryCustomerSales"

  6. #6
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    what is your table structure?
    what is your formula?
    what's the SQL code you're using?

    Need more information than you supplied?

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

Similar Threads

  1. Replies: 5
    Last Post: 12-26-2013, 06:12 AM
  2. Replies: 6
    Last Post: 12-11-2013, 09:27 PM
  3. Replies: 0
    Last Post: 12-13-2012, 03:18 AM
  4. Replies: 1
    Last Post: 12-24-2011, 08:48 AM
  5. Replies: 5
    Last Post: 06-30-2011, 02:24 AM

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