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

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
53,699
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,699
Office Version
365
Platform
Windows
You are welcome.
Glad I was able to help!
:)
 

Watch MrExcel Video

Forum statistics

Threads
1,102,630
Messages
5,488,004
Members
407,617
Latest member
Samanthad2007

This Week's Hot Topics

  • Timer in VBA - Stop, Start, Pause and Reset
    [CODE=vba][/CODE] Option Explicit Dim CmdStop As Boolean Dim Paused As Boolean Dim Start Dim TimerValue As Date Dim pausedTime As Date Sub...
  • how to updates multiple rows in muliselect listbox
    Hello everyone. I need help with below code. code is only chaning 1st row in mulitiselect list box. i know issue with code...
  • Delete Row from Table
    I am trying to delete a row from a table using VBA using a named range to find what I need to delete. My Range is finding the right cell. In the...
  • Assigning to a variable
    I have a for each block where I want to assign the value in column 5 of the found row to the variable Serv. [CODE=vba] For Each ws In...
  • Way to verify information
    Hi All, I don't know what to call this formula, and therefore can't search. I have a spreadsheet with information I want to reference...
  • Active Cell Address – Inactive Sheet
    How to use VBA to get the cell address of the active cell in an inactive worksheet and then place that cell address in a location on the current...
Top