Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Subtract two expressions in a Query 1

Status
Not open for further replies.

Comp2008

Technical User
Oct 8, 2008
32
US
I have two expressions that I want to Subtract.
Code 1:
Abs(Sum([BDC Info Table].[Pre-Owned or New]="New" And ([BDC Info Table].[Sold Date]<=#12/1/2008#) And ([BDC Info Table].[Sold Date]>=#11/3/2008#))) AS [CountNew]
And
Code 2:
Abs(Sum([BDC Info Table].[Status]="Sold Not Set" And ([BDC Info Table].[Sold Date]<=#12/1/2008#) And ([BDC Info Table].[Sold Date]>=#11/3/2008#))) AS [CountSoldNotSet]

Both of them individually work without any problem. Does any have a good way to subtract [CountNew] - [CountSoldNotSet] ? Logically, would be:
Code:
Abs(Sum([BDC Info Table].[Pre-Owned or New]="New" And ([BDC Info Table].[Sold Date]<=#12/1/2008#) And ([BDC Info Table].[Sold Date]>=#11/3/2008#))) - Abs(Sum([BDC Info Table].[Status]="Sold Not Set" And ([BDC Info Table].[Sold Date]<=#12/1/2008#) And ([BDC Info Table].[Sold Date]>=#11/3/2008#)))AS [Total Sold]
But, It doesn’t work.
Any help would be greatly appreciated
Comp2008
 
Hi,

Let's evaluate the expressions inside the SUM...
Code:
[BDC Info Table].[Pre-Owned or New]="New" 
([BDC Info Table].[Sold Date]<=#12/1/2008#)  
([BDC Info Table].[Sold Date]>=#11/3/2008#)
each of these three expressions evaluate to either TRUE or FALSE. So what are you SUMMING?

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Expression 1 (Code 1) Sums "CountNew" within 11/03/2008 and 12/01/2008

Expression 2 (Code 2) Sums "CountSoldNotSet" within 11/03/2008 and 12/01/2008

Now What I want to Sum is: (Expression 1) minus (Expression 2)
 
What happens when you run just expression 1 and expressrion 2 separately?

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Both expressions run without any problem separately. The problem is when I Subtract (Expression 1) Minus (Expression 2) It doesn't give me the right answer

Comp2008
 
This is like pulling teeth. Help yourself out.

What results did you get running separately and what result did you get with the subtraction?

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Give a little more time and I'll give more details
 
I’m sorry SkipVought for not answering before. I really appreciate your help. This is the expression that I was looking for. I change the approach a little bit and It works perfectly.
Code:
Abs(Sum([BDC Info Table].[Pre-Owned or New]="New" And ([BDC Info Table].[Status]="Active" And ([BDC Info Table].[Sold Date]<=#01/31/2009#) And ([BDC Info Table].[Sold Date]>=#01/3/2009#)))) + Abs(Sum([BDC Info Table].[Pre-Owned or New]="Pre-Owned" And ([BDC Info Table].[Status]="Active" And ([BDC Info Table].[Sold Date]<=#01/31/2009#) And ([BDC Info Table].[Sold Date]>=#01/3/2009#)))) AS CountSoldDate

Thank you again

Comp2008
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top