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

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
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,224,560
Messages
6,179,519
Members
452,921
Latest member
BBQKING

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