Forum

Notifications
Clear all

array formula to count unique value in a filtered table

10 Posts
4 Users
0 Reactions
76 Views
(@tinak)
Posts: 39
Trusted Member
Topic starter
 

Hi everyone, I have a table with a lot of duplicated IDs, want to count unique ID when filter is on. I came across a formula online then copy it to my spreadsheet, but it is not working. How does array formula work?

=sum(--(frequency(if(subtotal(3,offset(Table1[ID],match(row(Table1[ID]),row(Table1[ID])-1,0,1)),countif(Table1[ID],"<"&Table1[ID]),""),countif(Table1[ID],"<"&Table1[ID]))>0))

many thanks!

 
Posted : 23/06/2020 9:05 pm
(@purfleet)
Posts: 412
Reputable Member
 

Hi Tina

Can you please upload an example workbook so that we dont have to spend time recreating the data.

https://www.myonlinetraininghub.com/excel-forum/forum-rules-and-guides/read-this-first

 
Posted : 24/06/2020 1:24 am
(@tinak)
Posts: 39
Trusted Member
Topic starter
 

sorry that forgot about it. just attached the file.

wanted to count unique ID if filtering different fund. thanks

 
Posted : 24/06/2020 2:19 am
(@debaser)
Posts: 837
Member Moderator
 

I think this works:

 

=SUM(--(FREQUENCY(IF(SUBTOTAL(3,OFFSET(Table1[ID],ROW(Table1[ID])-MIN(ROW(Table1[ID])),0,1)),COUNTIF(Table1[ID],"<"&Table1[ID]),""),COUNTIF(Table1[ID],"<"&Table1[ID]))>0))

 

It needs to be array entered using Ctrl+Shift+Enter unless you're on O365.

 
Posted : 24/06/2020 4:40 am
Philip Treacy
(@philipt)
Posts: 1630
Member Admin
 

Hi Tina,

An alternative, you could use the new LET function (if you have it)

 

=LET(Unique_ID,UNIQUE(SUBTOTAL(105,OFFSET(F2,ROW(Table1[ID])-MIN(ROW(Table1[ID])),0))),

        Filtered_ID,FILTER(Unique_ID,Unique_ID>0),

        Filtered_Count,COUNT(Filtered_ID),

        Res,Filtered_Count,

        Res)

 

If you don't have LET you can put this into a cell, say H1

 

=UNIQUE(SUBTOTAL(105,OFFSET(F2,ROW(Table1[ID])-MIN(ROW(Table1[ID])),0)))

 

and then in I1 

 

=COUNTIF(H1#,">0")

 

COUNTIF requires a range so you can't wrap it around UNIQUE which returns an array.

You can read about the 'old style' array formulae here and the new dynamic arrays

Regards

Phil

 
Posted : 24/06/2020 8:41 am
(@tinak)
Posts: 39
Trusted Member
Topic starter
 

Thanks Velouria. I am not using O365, and I keep getting message 'You've entered too many arguments for this function.' - I am frustrated now... 

 
Posted : 24/06/2020 7:54 pm
(@tinak)
Posts: 39
Trusted Member
Topic starter
 

Thanks Phil, I downloaded your file, but the formula results show as '#NAME?', I don't know why. 

I tried inputting the formula as you suggested, and got the same as above. is it any functionality of my excel not on? Really appreciated with your help!

 
Posted : 24/06/2020 8:04 pm
Philip Treacy
(@philipt)
Posts: 1630
Member Admin
 

Hi Tina,

My solution requires dynamic arrays which you won't have if you don't have O365.

Velouria's formula works for me - see H1 in attached file - but it must be entered by using CTRL+SHIFT+ENTER as it is an array formula, rather than a non-array formula you enter just by hitting the ENTER key.

Please read the links I provided which will explain about CSE (CTRL+SHIFT+ENTER) array formulae.

Regards

Phil

 
Posted : 24/06/2020 8:17 pm
(@tinak)
Posts: 39
Trusted Member
Topic starter
 

Thanks for your prompt reply! Does this formula work if the table has a query link behind? I still couldnt get Velouris's formula work on my spreadsheet.

 
Posted : 24/06/2020 8:34 pm
Philip Treacy
(@philipt)
Posts: 1630
Member Admin
 

Hi Tina,

It should work fine.

Did my formula work for you in the file I attached to my last post?

Maybe you need to attach your file where it's not working so we can have a look.

Phil

 
Posted : 24/06/2020 11:20 pm
Share: