Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 12th, 2007, 05:07 PM
Authorized User
Join Date: Sep 2003
Location: , , .
Posts: 83
Thanks: 0
Thanked 0 Times in 0 Posts
Default Subtraction in an Access Query

Hello everyone,

I need a query where I calculate the net profit (or loss) in the given
transactions. So, I have to sum up all the positive value transactions
and subtract (actually add since the sum here will be negative) the
sum of all negative value transactions.

So, I have a table called Records_T which holds a field called Amount.

I can calculate the sum of all +ve records as follows:

SELECT Sum(Records_T.Amount) AS AMOUNT FROM Records_T WHERE

Similarly, the negative records sum is:

SELECT Sum(Records_T.Amount) AS AMOUNT FROM Records_T WHERE

Now, how can I combine these queries so that I get the sum of the
values returned by these two queries??

Thanks for any help you can give me. Really appreciate it.

Reply With Quote
  #2 (permalink)  
Old April 13th, 2007, 04:32 AM
Registered User
Join Date: Apr 2007
Location: London, London, United Kingdom.
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts

Create a query via the database and insert the required table

Select the Records_T.Amount field into the query grid.

On the tool bar, click on the totals symbol (the sigma or Greek S) and check that the totals row appears in the query grid.

Select sum from the drop down list for the field "Amount" in this row.

Run the query and it will add up both the negative and positive values to give an overall sum

You can of course filter this for values greater than or less than 0 via the criteria.

Hope this helps

Reply With Quote
  #3 (permalink)  
Old April 13th, 2007, 06:49 AM
Friend of Wrox
Points: 4,007, Level: 26
Points: 4,007, Level: 26 Points: 4,007, Level: 26 Points: 4,007, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG

Unless you need to show the positives and the negatives separately, why even separate the two to then later add? Just simply add them ALL to start with. The negative ones will subtract out of the positive ones anyway.

Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
subtraction operator overload arnie6 C++ Programming 0 April 19th, 2005 07:57 AM
need access query kale_tushar Access 2 January 3rd, 2005 05:26 AM
Dates Subtraction akhamis SQL Language 1 December 2nd, 2004 04:38 PM
subtraction collie SQL Server 2000 3 November 26th, 2004 01:03 AM
Access: need a Query. please help me... alienscript Access VBA 1 December 14th, 2003 01:02 PM

All times are GMT -4. The time now is 11:25 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.