Solved

Expression in a query

Posted on 2014-01-22
5
211 Views
Last Modified: 2014-01-22
Using query designer I have this code:

TouringCount: Abs(Count([ID]) And [PublicActivityCode]="GT")

Which doesn't work.  I'm trying to count the records (ID) where PublicActivityCode] = "GT" or "ST".

It needs to be an expression because I have more of these types of fields to add.
0
Comment
Question by:SteveL13
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 14

Expert Comment

by:Bill Ross
ID: 39800074
Hi,

Change the query to group by
Put [ID] as a count field in the query
Make criteria  [PublicActivityCode]="GT"

Regards,

Bill
0
 
LVL 14

Expert Comment

by:Bill Ross
ID: 39800086
Hi,

You can also create a field using the expression

dcount("ID",yourtable,"PublicActivityCode='GT'")

but this will be slower.

Regards,

Bill
0
 
LVL 14

Expert Comment

by:Bill Ross
ID: 39800089
FYI - ABS is not required.  Count can never be <0.
0
 
LVL 51

Accepted Solution

by:
Gustav Brock earned 250 total points
ID: 39800182
You can use:

TouringCount: Sum(Abs([PublicActivityCode]="GT" Or [PublicActivityCode]="ST"))

/gustav
0
 
LVL 38

Assisted Solution

by:PatHartman
PatHartman earned 250 total points
ID: 39800409
Functions in a query operate over the domain of the recordset.  So, Count(ID) returns a count of non-null values of ID contained in the recordset.  It cannot be constrained by criteria.  The simplest way to get a count of all values for a particular field is with this type of query:

Select PublicActivityCode, Count(*) As RecCount
From YourTable
Group By PublicActivityCode;

You will get a list like:
GT, 2345
ST, 123
AB, 445
xx, 3939
, 2
, 3

Notice the last two.  One will be the count of null values and the other will be the count of ZLS values.

If you want all the values returned as a single row, create a crosstab of the totals query.
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question