Results 1 to 7 of 7
  1. #1
    anoob is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jan 2011
    Posts
    60

    Sum Where Field?

    Hello, this is a quick one:

    I have a field that shows the total amount due for all my clients, this is based off a query and set up as follows:

    Code:
    =Sum([JobAndInvoiceData]![AmountDue])
    So right now it says essentially - Sum the value of all money due

    I would like it to only add the fields where another field named "Status" contains the value "Invoiced". So something like this:

    =Sum([JobAndInvoiceData]![AmountDue] WHERE [Status].Invoiced)

    I am not sure how to properly type this though - or if "where" is even usable.

    Any ideas?
    Many thanks.

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Add another field to your query that only has a non zero value when [Status] = "invoiced". Then Sum this field instead. As you suspected, there is *no* WHERE condition in the Sum() function as there is with the Domain functions.

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    I like Allan's solution. It can be done with a textbox:

    =Sum(IIf(Status = "Invoiced", AmountDue, 0))
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    anoob is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jan 2011
    Posts
    60
    Both of these are excellent solutions - thank you very much for your help!

  5. #5
    anoob is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jan 2011
    Posts
    60
    Oh actually here is another quick question: Let's say I have a table that stores transactions from 5 years ago to present, is there a way to take this statement

    Code:
    =Sum(IIf(Status = "Invoiced", AmountDue, 0))
    And add something that will make it only apply to transactions in 2010? I believe there are several date-type functions - but I guess I'm not sure if I can wrap THIS code in some sort of Get Year function... any ideas?

    Thanks again!

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    =Sum(IIf(Status = "Invoiced" AND Year(TransactionDate) = 2010, AmountDue, 0))
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    anoob is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jan 2011
    Posts
    60
    I shall try this now... pbaldy I cannot thank you enough if this works!

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

Similar Threads

  1. Replies: 5
    Last Post: 01-20-2011, 11:36 PM
  2. Replies: 9
    Last Post: 12-15-2010, 01:44 PM
  3. Replies: 1
    Last Post: 11-13-2010, 12:57 PM
  4. Replies: 3
    Last Post: 11-05-2010, 03:10 PM
  5. Replies: 1
    Last Post: 02-26-2009, 11:31 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