Results 1 to 5 of 5
  1. #1
    megatronixs is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    91

    sum up the positive numbers in a column

    Hi all,



    I have a query running that gets data from a linked table. There is a column in the table that has negative numbers and positive number in it. I would like to sum up the positive numbers and show the rusults at the end of the query results.
    How to go about this in a query? the column/field is called [ammount_details]

    Greetings.
    Last edited by megatronixs; 11-18-2015 at 06:33 AM.

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Here's the general sql involved to get sum of ammount_details where values are >0. You need to supply the proper table name.
    Code:
    SELECT Sum(ammount_details) AS SumOfammount_details
    FROM YourTableNameHere
    HAVING (((Sum(ammount_details))>0));

  3. #3
    InsuranceGuy is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Aug 2015
    Location
    Colorado
    Posts
    126
    Quote Originally Posted by orange View Post
    Here's the general sql involved to get sum of ammount_details where values are >0. You need to supply the proper table name.
    Code:
    SELECT Sum(ammount_details) AS SumOfammount_details
    FROM YourTableNameHere
    HAVING (((Sum(ammount_details))>0));
    Hi orange, I think you need to use a where condition instead of a having condition. Having will check after the sum. Instead:

    Code:
    select sum(amount) from table where [amount]>0
    Cheers,

    Jeff

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Good point. I built the query with Access query designer using Totals (sigma) and got the original SQL.

    You are correct, the WHERE clause will evaluate the positive/negative of each ammount_details before summing.

    So proper sql
    Code:
    SELECT Sum(ammount_details) AS SumOfammount_details
    FROM YourTableNameHere
    WHERE  (ammount_details) >0 ;

  5. #5
    megatronixs is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    91
    Hi all,

    Thanks a lot. I was a few days absent and had not chance to check it out.

    Greetings.

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

Similar Threads

  1. Replies: 1
    Last Post: 10-22-2014, 01:28 PM
  2. Replies: 7
    Last Post: 06-29-2013, 06:01 PM
  3. Show only positive numbers
    By Derrick T. Davidson in forum Reports
    Replies: 2
    Last Post: 03-27-2013, 01:11 AM
  4. Replies: 2
    Last Post: 09-10-2009, 05:42 AM
  5. Suming Positive Numbers Only
    By jbarrum in forum Access
    Replies: 5
    Last Post: 04-24-2009, 03:51 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