Results 1 to 4 of 4
  1. #1
    mauro27 is offline Novice
    Windows XP Access 2003
    Join Date
    Apr 2010
    Posts
    2

    Question Summarize on different columns and substract

    Hi,



    I have a broad understanding of SQL (views, tables, etc.) but I'm a newby in MS Access. My supervisor is asking me to prepare an SQL statement / query in MS Access to get the summarized invoices (in positive amount), credit notes (originally in positive amount) and then the substraction of both for each customer. To give a more precise example, this the original data and the result I would need.

    Type 1 = invoice
    Type 2 = credit note


    Original table: CUSTOMERDATA

    Type Customer Amount
    1 Cust_A 100
    2 Cust_A 8
    1 Cust_A 18
    1 Cust_B 200
    2 Cust_B 35
    2 Cust_B 25

    Final Report
    Customer Invoices_SUM CreditNotes_SUM Total
    Cust_A 118 8 110
    Cust_B 200 60 240

    I was trying to create an SQL view to get this but in my Access version I cannot create VIEWS. What code could I use to get this report?

    Thanks in advance,
    Mauro.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You can Sum a formula:

    IIf(TypeField = 1, AmountField, 0)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    ConneXionLost's Avatar
    ConneXionLost is offline Simulacrum
    Windows XP Access 2003
    Join Date
    Jan 2010
    Location
    Victoria, Canada
    Posts
    291
    Hi Mauro,

    An Access query is the equivalent of the SQL View.

    Code:
    SELECT CUSTOMERDATA.Customer, Sum(IIf([Type]=1,[Amount],0)) AS Invoices_SUM, Sum(IIf([Type]=2,[Amount],0)) AS CreditNotes_SUM, [Invoices_SUM]-[CreditNotes_SUM] AS Total
    FROM CUSTOMERDATA
    GROUP BY CUSTOMERDATA.Customer;
    Cheers,

  4. #4
    mauro27 is offline Novice
    Windows XP Access 2003
    Join Date
    Apr 2010
    Posts
    2
    Quote Originally Posted by ConneXionLost View Post
    Hi Mauro,

    An Access query is the equivalent of the SQL View.

    Code:
    SELECT CUSTOMERDATA.Customer, Sum(IIf([Type]=1,[Amount],0)) AS Invoices_SUM, Sum(IIf([Type]=2,[Amount],0)) AS CreditNotes_SUM, [Invoices_SUM]-[CreditNotes_SUM] AS Total
    FROM CUSTOMERDATA
    GROUP BY CUSTOMERDATA.Customer;
    Cheers,

    Perfect, thanks!

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

Similar Threads

  1. Cumulative sum (columns)
    By ravens in forum Queries
    Replies: 1
    Last Post: 03-02-2010, 08:14 PM
  2. Add columns if not exists
    By ysrini in forum Access
    Replies: 1
    Last Post: 02-16-2010, 06:39 PM
  3. using VBA to freeze columns
    By bdaniel in forum Forms
    Replies: 1
    Last Post: 02-12-2010, 05:36 AM
  4. Columns in a Listbox
    By craigalaniz in forum Access
    Replies: 3
    Last Post: 01-07-2010, 01:11 PM
  5. Adding Two Columns
    By arthura in forum Queries
    Replies: 6
    Last Post: 05-01-2009, 08:38 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