473,386 Members | 1,804 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,386 software developers and data experts.

Aggregate functions

Ok, so I have query with the following criteria: Total Classes: Count(IIf([tblDocuments]![Red]+[tblDocuments]![blue]+[tblDocuments]![green]=Yes,1,Null)). This query has some proprietary info in it so I can't show the real words so I used colors. but anyway, I want it to count the number of classes, except when there is a closed date for the class, I don't want it to count the closed class.
May 23 '16 #1
9 954
NeoPa
32,556 Expert Mod 16PB
Do you realise your SQL there is checking for one, and only one, of those items to resolve to Yes?

Booleans used in arithmetic don't cause the arithmetic to be Boolean Arithmetic. IE. Each Boolean True resolves to -1 (In Jet/ACE - 1 in SQL Server) and Yes, is also True of course.

Thus, any more, or less, of those values that are True will make the result either less than -1 or 0. Compare that to Yes (-1) and it just won't match.

For an answer to your full question you'll need to include the full question, of course. It's perfectly acceptable to obscure names as you have done, but if you only post a fraction of the relevant details you may wait a while for help.
May 23 '16 #2
PhilOfWalton
1,430 Expert 1GB
I think it would be helpful to know what possible values one could expect from tblDocuments!Red.
for example between - 1000 and 5000
0 or -1 only
Between Aaron & Zebedee

I assume Blue & Green will give similar results

Phil
May 23 '16 #3
let me see if I can say this without getting in trouble...LOL. I have 3 different document sets. Green documents, blue document, and red documents. I want the query to count each color and return a total. But if a document has a destruction date, I don't want the query to count it. All the documents are represented by a checkbox. So for example if I have a document and it is red, I check the red box, if it is blue I check the blue box, ect... but when I get rid of that document it has a destruction date. so I want to count each color document for a total color but if it has a destruction date don't count it..Thanks for all the help
May 23 '16 #4
PhilOfWalton
1,430 Expert 1GB
So let's just deal with one document set
Expand|Select|Wrap|Line Numbers
  1. DCount("Documents", "GreenDocuments", "DestructDate is Null")
  2.  
This should count all the documents without a destruction date.

Then all you have to do is a similar thing for the other colours and add them up.

You must appreciate that unless we have the table details, or at least an accurate layout of the table, we can't guarantee the answer.

Something like
Expand|Select|Wrap|Line Numbers
  1. TblRedDocuments
  2.     RedDocID               Autonumber
  3.     RedDocName             Text
  4.     RedDocDectructDate     Date
  5.  
then we would be much better able to help

Phil
May 23 '16 #5
Here is a sample of my DB.


May 24 '16 #6
PhilOfWalton
1,430 Expert 1GB
In your sample data, in Table 1, Document 4 has no colours selected, and document 5 has both blue & green.
Is this a typo?
What totals are you expecting for each of the three columns?

Phil
May 24 '16 #7
yeah just typos, I want the total of each color in each column and then I will add a total column for all colors, but once again, if there is a destroyed date, don't count it.
May 24 '16 #8
NeoPa
32,556 Expert Mod 16PB
You may be looking for something like :
Expand|Select|Wrap|Line Numbers
  1. Total Classes: -Sum(IIf([DocumentDestroyed] Is Null,[chkRed]+[chkBlue]+[chkGreen],0))
Bear in mind, this relies on the value of a Yes column equating to -1. It also relies on your having controls as named tied to the fields.

Aggregate functions (as used here) deal with values on the report or form.
Domain Aggregate functions work with a specified record source.

Your query picture doesn't give much away. If you want to share your query then the SQL is a much more reliable way to do so. Otherwise, a description of what you're doing is required, which is still missing. You give a couple of details but there are still gaps in the overall picture. Are you including all records in the results? Are they grouped in any way (If not then you'll only get one record in the result)?

PS. Please make sure you fix any typos before posting in future. It's a shame to waste so much of people's time for the simple want of a little care.
May 24 '16 #9
PhilOfWalton
1,430 Expert 1GB
I would add that if there are only 3 types of properties (red, green & blue) for your document, then your table structure is just about acceptable. To me it doesn't really look normalised and I would have a separate table of "Colours"
Expand|Select|Wrap|Line Numbers
  1. TblColours
  2.     ColourID          Auto    PK
  3.     Colour            Text    (No duplicates)
  4.  
And in your Docoment table
Expand|Select|Wrap|Line Numbers
  1. TblDocuments
  2.     DocID      Auto   PK
  3.     DocName    Text
  4.     ColourID   Long   FK   Required
  5.  
That way there is no possibility of having anything but 1 "colour" per document.

Phil
May 24 '16 #10

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

Similar topics

1
by: Jason | last post by:
I have a complex statement that is used in a SELECT statement. After all my calculations I need to do an additional filter on the results. Can I use an alias anywhere or is the AS clause just for...
6
by: Steven An | last post by:
Howdy, I need to write an update query with multiple aggregate functions. Here is an example: UPDATE t SET t.a = ( select avg(f.q) from dbo.foo f where f.p = t.y ), t.b = ( select sum(f.q)...
1
by: Job Lot | last post by:
Is it possible to use Aggregate functions with GROUP BY Clauses on DataTable. I have a DataTable with following values: Date Amount Int Balance 1/1/2004 5000.00 50.00 5050.00...
2
by: jc | last post by:
Hi. Just as we have AVG(COLUMN_NAME) and MAX(COLUMN_NAME) how can I write my own variation of a such a function. If I can appreciate how to do this, then I hopefully I can write a...
3
by: eddiec | last post by:
hi everyone, I have a report in an adp that uses aggregate functions in its record source and I am trying to figure out how to filter the records displayed in the report: DoCmd.OpenReport...
10
by: neb | last post by:
Dear member of the forum, Ms access has built-in aggregate function like: -Sum, Max, First, Avg, ... Is it possible to build user-defined aggregate? (if you have any clue, do not hesitate to...
0
by: Not Me | last post by:
Hey, I have a report featuring a handful of subreports, a field taking values from the main record source, and a field in the report footer which displays the sum of values in said field. The...
5
by: David Garamond | last post by:
What do people think of adding some more aggregate functions. These are the ones that MySQL has and PG doesn't: - STD/STDDEV - VARIANCE - BIT_OR - BIT_AND - GROUP_CONCAT (for strings, added...
5
by: Dean | last post by:
Has anyone toiled with creating/using alternate domain aggregate functions? I have been messing with that a little. The one recordsource I have been working indicates I get 20 to 40% savings in...
3
by: gobwash | last post by:
Do aggregate functions (sum, count, min, max) inherently cause table locks? More concretely, would the following query typically result in a table lock? select sum(quantity) as total from...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.