473,395 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Count records by ID that are Null

294 256MB
I am trying to figure out how many payouts remain for each award per year, so I can say "you have been paid out 1 out of 3 installments."

The data will look like this:
PayoutID PayoutDate PayoutUnits CheckRequestDate AwardID
1111 2/7/2014 5 2/6/2014 1234
1112 2/7/2015 5 1234
1113 2/7/2016 5 1234

I am trying to use DCount for the number of payouts remaining. (when CheckRequestDate IS Null) .. When I try
Expand|Select|Wrap|Line Numbers
  1. DCount("AwardID","PayoutTbl","CheckRequestDate Is Null")
It gives me a count of the entire table (43) when in this case it should return 2.

The SQL is here:
Expand|Select|Wrap|Line Numbers
  1. SELECT Sum([PayoutTbl]![PytUnits]*[NAV_Tbl]![NetAssetValue]) AS PytGross, CheckTbl.CheckDate, Sum(PayoutTbl.PytUnits) AS SumOfPytUnits,
  2.  CheckTbl.TaxFederal, CheckTbl.TaxState, [CheckTbl]![TaxFicaR]+[CheckTbl]![TaxFicaM] AS [Fica Tax], 
  3. CheckTbl.TaxLocal, AssociateTbl.EmployeeID, AssociateTbl.AstFirstName, AssociateTbl.AstLastName, AssociateTbl.HomeStreet, AssociateTbl.HomeCity,
  4.  AssociateTbl.HomeState, AssociateTbl.HomeZip, DCount("AwardID","PayoutTbl","CheckRequestDate Is Not Null") AS Expr1, PayoutTbl.PytID
  5. FROM AssociateTbl INNER JOIN ((NAV_Tbl INNER JOIN (CheckTbl INNER JOIN PayoutTbl ON CheckTbl.CheckNo = PayoutTbl.CheckNo) ON NAV_Tbl.NAV_Date = PayoutTbl.PytNAV) 
  6. INNER JOIN AwardTbl ON PayoutTbl.AwardID = AwardTbl.AwardID) ON AssociateTbl.EmployeeID = AwardTbl.EmployeeID
  7. GROUP BY CheckTbl.CheckDate, CheckTbl.TaxFederal, CheckTbl.TaxState, [CheckTbl]![TaxFicaR]+[CheckTbl]![TaxFicaM],
  8.  CheckTbl.TaxLocal, AssociateTbl.EmployeeID, AssociateTbl.AstFirstName, AssociateTbl.AstLastName, AssociateTbl.HomeStreet,
  9.  AssociateTbl.HomeCity, AssociateTbl.HomeState, AssociateTbl.HomeZip, DCount("AwardID","PayoutTbl","CheckRequestDate Is Null"), PayoutTbl.PytID;
I know it's extensive, however the Count is the only thing calculating incorrectly.
Feb 7 '14 #1

✓ answered by NeoPa

I'm pretty sure that whatever you want must match the [AwardID] of the current record. That said, it isn't clear how your data indicates whether or not a payment has been made or not.

As such, I would expect the DCount() code to be similar to :
Expand|Select|Wrap|Line Numbers
  1. DCount("*","PayoutTbl","([AwardID]=" & [AwardID] & ") AND (...)")
The ellipses need to be determined and replaced when we know what else we're looking for.

PS. You'd need to GROUP BY [AwardID] but set the DCount() as an expression. It shouldn't need to appear in the GROUP BY clause.
Excellent. Then you want something like :
Expand|Select|Wrap|Line Numbers
  1. DCount('*','PayoutTbl','([AwardID]=' & [AwardID] & ') AND ([CheckRequestDate] Is Null)')
The quotes used are correct for SQL.

19 1936
Rabbit
12,516 Expert Mod 8TB
The DCount in your SQL doesn't match the DCount in the code block above it.
Feb 7 '14 #2
mcupito
294 256MB
Sorry! I had accidentally tried something else and did not realize it. It is updated.
Feb 7 '14 #3
Rabbit
12,516 Expert Mod 8TB
But you updated it to "Is Not NULL". I thought you were trying to count all the records that are null?
Feb 7 '14 #4
mcupito
294 256MB
Either way will work, really. They are both going to be used the same. I will update them back to Null due to the question title. Sorry for the confusion.
Feb 7 '14 #5
NeoPa
32,556 Expert Mod 16PB
I'm pretty sure that whatever you want must match the [AwardID] of the current record. That said, it isn't clear how your data indicates whether or not a payment has been made or not.

As such, I would expect the DCount() code to be similar to :
Expand|Select|Wrap|Line Numbers
  1. DCount("*","PayoutTbl","([AwardID]=" & [AwardID] & ") AND (...)")
The ellipses need to be determined and replaced when we know what else we're looking for.

PS. You'd need to GROUP BY [AwardID] but set the DCount() as an expression. It shouldn't need to appear in the GROUP BY clause.
Excellent. Then you want something like :
Expand|Select|Wrap|Line Numbers
  1. DCount('*','PayoutTbl','([AwardID]=' & [AwardID] & ') AND ([CheckRequestDate] Is Null)')
The quotes used are correct for SQL.
Feb 7 '14 #6
mcupito
294 256MB
A payment has been made when the CheckRequestDate has a date (Is Not Null) .. I will look into your solution when I return from lunch. Thanks, @NeoPa.
Feb 7 '14 #7
NeoPa
32,556 Expert Mod 16PB
Excellent. Then you want something like :
Expand|Select|Wrap|Line Numbers
  1. DCount('*','PayoutTbl','([AwardID]=' & [AwardID] & ') AND ([CheckRequestDate] Is Null)')
The quotes used are correct for SQL.
Feb 7 '14 #8
mcupito
294 256MB
Works magical, NeoPa. Thank you. I would have never guessed the AwardID aspect.

It seems like it is taking a performance hit, why do you think that is?
Feb 7 '14 #9
NeoPa
32,556 Expert Mod 16PB
Always a pleasure M :-)
Feb 7 '14 #10
mcupito
294 256MB
@NeoPa how would the code differ if I included the AwardDate in the query? I was just informed the format needs to be changed for the query, and the SQL you wrote is giving me incorrect data now that I included the AwardDate in the query.

2 Payouts are now 4, and 8 remaining payouts are now 16.
Feb 7 '14 #11
NeoPa
32,556 Expert Mod 16PB
Included it in what way M?

Your question needs to be expressed more specifically.
Feb 8 '14 #12
mcupito
294 256MB
You can just say Mark if you want.. I feel odd being referred to as a letter haha..

As the query functioned prior to the new request, the code you wrote worked perfectly, and returned the correct information. I had also reversed the logic to find the count for "Is Not Null" and I added them both together to get the total number of payouts.

Pleasantly enough, the records are all going to be grouped by the date the awards were given instead of the way they were grouped. So, when I incorporated this into the query, all of numbers doubled for the DCount functions.

"2 Payouts are now 4" = Payouts were the number of "Is Not Null" CheckRequestDates
"8 remaining payouts are now 16" = The DCount you wrote, which retrieved the number of "Null" CheckRequestDate fields.

It seems as though adding in the AwardDate through a wrench into the query and I tried to play around with the DCount by changing fields, but I was only screwing it up worse.

What are your thoughts? And where did you learn the " '([AwardID]=' & [AwardID] & ') " piece?

Although this is my last MS Access project, it is good knowledge (for perhaps other users trying to do the same thing!)
Feb 8 '14 #13
NeoPa
32,556 Expert Mod 16PB
I was being circumspect about your name Mark. If you share information with me that you haven't made public then I have to be careful not to make it public on your behalf. Just in case it's important to you to keep it private ;-) Now I'm clear you're happy then I will be less careful.

As for your requests for further clarification on related issues, I'm afraid I didn't really understand what you were saying clearly enough to make sense of it :-( I would need a very precise understanding for that.

Where did I learn about "'([AwardID]=' & [AwardID] & ')"?
I'm really not sure which bit you want explaining. The double-quotes are yours. The single quotes are used by SQL to delineate string literals. Everything between the quotes is passed as is, whereas the stuff outside of the quotes is interpreted by SQL as a reference or as SQL code. Thus 'XXX' & [AwardID] & 'YYY' comes out as (EG. When [AwardID]=324.) XXX324YYY. This is what SQL tries to interpret. In the actual SQL we passed it comes out as :
Expand|Select|Wrap|Line Numbers
  1. ([AwardID]=324) AND ([CheckRequestDate] Is Null)
Clearly, every time [AwardID] changes the number changes - but the rest of the string stays the same.

You'll see how that makes sense in SQL. I hope this helps.
Feb 9 '14 #14
mcupito
294 256MB
NeoPa, maybe if I post the old data results vs the new, it will be more easily understood.

When I include the 'AwardDate' into my query, it throws the Paid out / Remaining / Total units off. (It doubles them)

I need to keep the values from the code you wrote, and not have them double. I hope this is clearer.


Attached Images
File Type: jpg payoutnew.jpg (27.5 KB, 224 views)
File Type: jpg payoutmew.jpg (8.5 KB, 262 views)
Feb 10 '14 #15
NeoPa
32,556 Expert Mod 16PB
That helps very little I'm afraid Mark. The data's not legible even when zoomed in and it doesn't come with the associated SQL.

If you were to strip the SQL right down to only those elements that are important to the question and post both versions (as text in [code] tags) and include with that a limited set of data to go with it (One set for each SQL), then I'd have something from which I could try to work out what your question is.
Feb 10 '14 #16
mcupito
294 256MB
Sure - sorry for the delay.

In the query, if I
Expand|Select|Wrap|Line Numbers
  1. GROUP By AwardTbl.AwardUnits
then the numbers in these lines of SQL double:
Expand|Select|Wrap|Line Numbers
  1. Remaining: Sum(DCount('*','PayoutTbl',' ([PayoutTbl]![AwardID]=' & [PayoutTbl]![AwardID] & ') AND([CheckRequestDate] Is Null)'))
  2. PaidOut: Sum(DCount('*','PayoutTbl','([PayoutTbl]![AwardID]=' & [PayoutTbl]![AwardID] & ') AND ([CheckRequestDate] Is Not Null)'))
  3. Sum: Sum(DCount('*','PayoutTbl','([PayoutTbl]![AwardID]=' & [PayoutTbl]![AwardID] & ') AND ([CheckRequestDate] Is Null)')+DCount('*','PayoutTbl','([PayoutTbl]![AwardID]=' & [PayoutTbl]![AwardID] & ') AND ([CheckRequestDate] Is Not Null)'))
  4.  
If I DON'T Group By [AwardTbl].[AwardDate], the numbers aren't doubled.

The unfortunate reality is that I need the AwardDate to group them by year on the report.
Feb 11 '14 #17
NeoPa
32,556 Expert Mod 16PB
Ah. The penny is starting to drop.

I suspect the culprit in this case is that you're using Sum() of the DCount() calls, whereas they should be included as Expression in your QueryDef.

Alternatively, of course, if the DCount() should actually be a Count(), then this simplifies everything and also makes it work very much more efficiently. That may be a question for another thread of course.
Feb 12 '14 #18
mcupito
294 256MB
Ah! That's it. Thanks, NeoPa! Sorry for the long drawn-out contusion of an issue.
Feb 12 '14 #19
NeoPa
32,556 Expert Mod 16PB
No worries Mark. We got there in the end ;-)
Feb 12 '14 #20

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

Similar topics

4
by: Sjef ten Koppel | last post by:
Hi, I've a small problem. I have a table in which one column is date. I want to count the records for statiscs in a temptable grouped by months lets say 12 months back. e.g. month 1 counts 164...
2
by: Pete | last post by:
I need to create a single query (Not a SQL query) against a single table that counts the number of records in the table, where the single field "tmp" contains specific string values If the field...
1
by: Etayki | last post by:
Hi! I am trying to find the number of records stored in my table within a MS SQL database. This is part of a Console Application. Here is my code: Sub RecordCount() Dim cmd2 As New...
5
by: Soccer5 | last post by:
Trying to Count records on a report that meet a certain criteria. Have a text box in the Report Footer that has the following in the Control Source: =Count(="S") This does not work. It...
6
markrawlingson
by: markrawlingson | last post by:
Hopefully someone can help me out with this, it's driving me nuts... I have two tables - We'll call them table1 and table2. Table1 holds event information, and table2 holds user registration data...
4
by: AccessHunter | last post by:
Hi, I have a table with the type of data as below, sorted as follows, Case (ascending), Loc (ascending) and Transaction Date (ascending). CASE LOC TRANSACTION DATE FACILITY...
5
by: phill86 | last post by:
Hi I want to be able to count records in a dao.querydef recordset but I keep getting the error message method or data member not found I have also tried to find out if the recordset is at...
5
by: sg2808 | last post by:
Hi, I have two tables, and which are in a many to many relationship via a junction table. It has the following field (relevant ones for this discussion): RuleID RuleName ProcessID
1
Fary4u
by: Fary4u | last post by:
code works fine it's counts the records but not bring updated record? is there any other way to count records ? Set rs = Server.CreateObject("ADODB.Recordset") strSQL = "SELECT...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.