Query Count

QandAdam

New Member
Joined
Jan 12, 2019
Messages
30
This is hopefully a simple one.

How can I count records based on criteria? So it would be a count of 'Active' ('Status' Field) for each 'Group'.

I'm looking to go from something like this:
GroupRecordIDStatus
ABC0001Active
ABC0002Closed
ABC0003Active
DEF0004Active

<tbody>
</tbody>
etc....

To this:
GroupActive Records
ABC13
DEF25

<tbody>
</tbody>

I've tried the below as a field in the query but it returns the wrong numbers:
[FONT=&quot]
Code:
[/FONT][/COLOR][COLOR=#2F2F2F][FONT=&quot]=DCount("[Group]", "tblRecords", "[SalesStatus] = 'Active'")[/FONT][/COLOR][COLOR=#2F2F2F][FONT=&quot]
[/FONT]
 
Last edited:

Some videos you may like

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
53,650
Office Version
365
Platform
Windows
This is really easy to do with an Aggregate (Totals) Query.
Create a new query adding all three of those fields.
Click on the Totals button in the menu of the Query Builder (look like a Sigma).
Under the "RecordID" field, change the new Totals row value from "Group By" to "Count".
Under the "Status" field, change the new Totals row value from "Group By" to "Where".
Add the word "Active" on the Criteria row of the "Status" field.
View your results.

You may wish to read up more on Aggregate/Totals queries to get a better understanding of how they work. You can find lots of articles and tutorials with a Google search.
 

QandAdam

New Member
Joined
Jan 12, 2019
Messages
30
This is really easy to do with an Aggregate (Totals) Query.
Create a new query adding all three of those fields.
Click on the Totals button in the menu of the Query Builder (look like a Sigma).
Under the "RecordID" field, change the new Totals row value from "Group By" to "Count".
Under the "Status" field, change the new Totals row value from "Group By" to "Where".
Add the word "Active" on the Criteria row of the "Status" field.
View your results.

You may wish to read up more on Aggregate/Totals queries to get a better understanding of how they work. You can find lots of articles and tutorials with a Google search.
AMAZING! That is easy! Thanks for the help and advice
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
53,650
Office Version
365
Platform
Windows
You are welcome.
Glad I was able to help!
:)
 

Watch MrExcel Video

Forum statistics

Threads
1,102,377
Messages
5,486,506
Members
407,549
Latest member
dommeehan

This Week's Hot Topics

Top