Count Unique Records in a Query

Moxioron

Active Member
Joined
Mar 17, 2008
Messages
436
Office Version
  1. 2019
Hello.

Trying to count unique records in just one field ... while getting totals in other columns. This is what I have ... I have highlighted the row I am having the issue with.

When I run the query, I get "At most one record can be returned by this subquery". Thank you

SELECT
Left([tbl_ROL150_Updated].[Merchant Name],10) AS [Merchant Name],
Count(Select Distinct [Member Number] From [tbl_ROL150_Updated] AS Total_Members),
Count(tbl_ROL150_Updated.[ROL Case #]) AS [CountOfROL Case #],
Sum(tbl_ROL150_Updated.Amount) AS SumOfAmount

FROM tbl_ROL150_Updated

WHERE (((tbl_ROL150_Updated.Disposition)="PC") AND ((tbl_ROL150_Updated.[Entry Date/Time]) Between [Start Date] And [End Date]))

GROUP BY Left([tbl_ROL150_Updated].[Merchant Name],10);
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
I would copy the subquery sql to a new query and test it to see why it is returning more than one record. It could be that you need DISTINCT ROW, or there are dupes of [Member Number] (which should be an issue) or you need to add the TOP predicate. I admit that I struggle with subqueries and this is where go for info
 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,606
Members
449,089
Latest member
Motoracer88

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