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:
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Group[/TD]
[TD]RecordID[/TD]
[TD]Status[/TD]
[/TR]
[TR]
[TD]ABC[/TD]
[TD]0001[/TD]
[TD]Active[/TD]
[/TR]
[TR]
[TD]ABC[/TD]
[TD]0002[/TD]
[TD]Closed[/TD]
[/TR]
[TR]
[TD]ABC[/TD]
[TD]0003[/TD]
[TD]Active[/TD]
[/TR]
[TR]
[TD]DEF[/TD]
[TD]0004[/TD]
[TD]Active[/TD]
[/TR]
</tbody>[/TABLE]
etc....

To this:
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Group[/TD]
[TD]Active Records[/TD]
[/TR]
[TR]
[TD]ABC[/TD]
[TD]13[/TD]
[/TR]
[TR]
[TD]DEF[/TD]
[TD]25[/TD]
[/TR]
</tbody>[/TABLE]

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:

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
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.
 
Upvote 0
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
 
Upvote 0
You are welcome.
Glad I was able to help!
:)
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,219
Members
452,619
Latest member
Shiv1198

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top