How can I count unique accounts?

chris-evans

Board Regular
Joined
Feb 19, 2002
Messages
73
Hi I have an access table with 5 fields:

1) Month of Joining
2) User ID
3) Date of transaction
4) Value of transaction
5) Country

I am wanting to count the number of unique user ID's in each month of joining for a specific country, e.g. the UK. Because there is a new row for every transaction, I can't just count the User ID's for each month as the query will duplicate the entries. I was thinking that the DCount query would work but i can't get it to.

My query was had three fields:

a) Month of Joining (grouped by)
b) Unique Users: DCount("[User ID]","My Table Name")
c) Country (with criteria = "uk")

This doesn't appear to work, could someone help me out where i am going wrong?

Many thanks.

Chris
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
One way is to do this in a series of two queries.

First Query
- Add your three fields (Month of Joining, User ID, and Country)
- Add the country criteria ("uk")
- Click on the Totals button to make this an Aggregate Query. This will add a Totals Row with the phrase "Group By" under each field

You will now have a query with all duplicates weeded out.

Now, create a second query based on your first query

Second Query
- Add all three fields from Query 1
- Click on the Totals button to make this an Aggregate Query. This will add a Totals Row with the phrase "Group By" under each field
- Under the User ID field, change the Totals Row from "Group By" to "Count"
- View the results

This should give you what you are looking for.
 
Upvote 0
Create a query to select DISTINCT, then query that query for the totals:
Code:
SELECT 
	TSub.UserID, 
	TSub.MonthJoined, 
	TSub.Country, 
	COUNT(TSub.UserID) AS TotalByCountryByMonth
FROM
	(
	SELECT DISTINCT
		UserID, 
		DateSerial(Year(JoinDate), Month(JoinDate)+1, 0) AS MonthJoined, 
		Country FROM Table2
	) TSub
GROUP BY 
	TSub.UserID, 
	TSub.MonthJoined, 
	TSub.Country
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,858
Members
449,051
Latest member
excelquestion515

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