By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,098 Members | 1,893 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,098 IT Pros & Developers. It's quick & easy.

Count two fields based on Date in a Query

P: 58
I'm trying to Count data in a Query Combining two different fields based on the "Date" the product was sold, and for some reason I get a wrong data. When I use only this expression, It works fine:
Code:
Count(IIf([BDC Info Table].[Sold Date]>=#11/1/2008#,0)) AS [CountNovSold]

But when I want to Count another field based on the same Date.
Code:
Count(IIf([BDC Info Table].[Status]="Sold Not Set",0) And (IIf([BDC Info Table].[Sold Date]>=#11/1/2008#,0))) AS [CountOfSold Not Set]


It gives me a wrong data. Apparently, It doesn't recognize the exact Date.
Any Help would be greatly appreciated

plaguna
Nov 10 '08 #1
Share this Question
Share on Google+
3 Replies


puppydogbuddy
Expert 100+
P: 1,923
Try it this way:

Expand|Select|Wrap|Line Numbers
  1. (Count(IIf([BDC Info Table].[Status]="Sold Not Set",0)) + Count(IIf([BDC Info Table].[Sold Date]>=#11/1/2008#,0))) AS [CountOfSold Not Set]
Nov 11 '08 #2

P: 58
Actually I want to retrieve [Status ]=“Sold not Set” when [Sold Date] is >=11/01/2008.
I found that Count will count all non-null values. That’s why I didn’t get the right data.
What do you think about this expression.
Code:

Expand|Select|Wrap|Line Numbers
  1. Abs(Sum([BDC Info Table].[Status]="Sold Not Set" And [BDC Info Table].[Sold Date]<#11/1/2008#)) AS [CountOfSold Not Set]
plaguna
Nov 17 '08 #3

puppydogbuddy
Expert 100+
P: 1,923
Actually I want to retrieve [Status ]=“Sold not Set” when [Sold Date] is >=11/01/2008.
I found that Count will count all non-null values. That’s why I didn’t get the right data.
What do you think about this expression.
Code:

Expand|Select|Wrap|Line Numbers
  1. Abs(Sum([BDC Info Table].[Status]="Sold Not Set" And [BDC Info Table].[Sold Date]<#11/1/2008#)) AS [CountOfSold Not Set]
plaguna
Does your expression work for you? Also, in regards to your statement count not including null values, you should be aware that Count(*) counts null and non-null values. Count([SomeField]) will only count non-null values.

If your expression above does not work, you can try this variation of the one I gave you previously that utilizes the null to zero function, which should convert your nulls to zeros in the count and give you the answer you are looking for.

Expand|Select|Wrap|Line Numbers
  1. nz(Count(IIf([BDC Info Table].[Status]="Sold Not Set",0)),0) + nz(Count(IIf([BDC Info Table].[Sold Date]>=#11/1/2008#,0))),0) AS [CountOfSold Not Set]
Nov 18 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.