Count Distinct and subtotal

dragonmouse

Board Regular
Joined
May 14, 2008
Messages
129
Office Version
  1. 2016
Platform
  1. Windows
I want to count distinct stock numbers J4:J1226
I'm using formula =SUMPRODUCT(1/COUNTIF(J4:J1226,J4:J1226)) and it works pleasantly. Now I want to add one more problem. When I filter out perhaps stock numbers worked by a particular person I want it to return a count distinct subtotal.

I can usually use =SUBTOTAL(3, J4:J1226) and it will return a count all the items in that range but t a "distinct" count. I filter on EMPLOYEE NAME in column A (SMITH). SMITH worked 100 products but only 29 of those products were "unique".

IDEAS?
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Try:

=SUM(SIGN(FREQUENCY(IF(SUBTOTAL(103,OFFSET(J4,ROW(J4:J1226)-ROW(J4),0))=1,MATCH(J4:J1226,J4:J1226,0)),ROW(J4:J1226)-ROW(J42)+1)))
confirmed with Control+Shift+Enter.
 
Upvote 0
Control+shift+enter, not just enter:

=SUM(IF(FREQUENCY(IF(SUBTOTAL(3,OFFSET(J4,ROW(J4:J1226)-ROW(J4),0)),IF(J4:J1226<>"",MATCH(J4:J1226,J4:J1226,0))),ROW(J4:J1226)-ROW(J4)+1),1))
 
Upvote 1
Oh MY GOODNES...It WORKS PERFECTLY. I would really love to understand the magic though. Could you explain how you came up with this...I've added it to my formulas list, but I don't understand the magic behind it but it's FABULOUS. Thank you so much.

I really wish I was better at this.
 
Upvote 0
I'm going to review that. I love this form so much. I'm so dumb but I look smart at work :)

Thank you so much. This is better than any class. I've taken classes, they just don't go far enough.
 
Upvote 0

Forum statistics

Threads
1,214,634
Messages
6,120,659
Members
448,975
Latest member
sweeberry

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