Formulas to count including Unique Numbers

Graham C1600

Board Regular
Joined
Feb 17, 2018
Messages
96
Office Version
  1. 365
Hi,

I've tried this before but ended up going around in circles because i was not asking the right questions. Hopefully the below will clear all this up.

[TABLE="width: 507"]
<colgroup><col><col><col><col span="3"></colgroup><tbody>[TR]
[TD]User ID[/TD]
[TD]Name[/TD]
[TD]Last Logon[/TD]
[TD]UTC[/TD]
[TD]Model[/TD]
[TD]Type[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Gary[/TD]
[TD]01/01/2019[/TD]
[TD]No[/TD]
[TD]AD[/TD]
[TD]COL[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Stephen[/TD]
[TD]02/01/2019[/TD]
[TD]No[/TD]
[TD]REL[/TD]
[TD]COL[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Brian[/TD]
[TD][/TD]
[TD]No[/TD]
[TD]REL[/TD]
[TD]COL[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Graham[/TD]
[TD]05/03/2019[/TD]
[TD]Yes[/TD]
[TD]REL[/TD]
[TD]SIM[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]Steve[/TD]
[TD][/TD]
[TD]No[/TD]
[TD]REL[/TD]
[TD]COL[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]Clare[/TD]
[TD]06/05/2019[/TD]
[TD]Yes[/TD]
[TD]REL[/TD]
[TD]SIM[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]Trev[/TD]
[TD][/TD]
[TD]Yes[/TD]
[TD]AD[/TD]
[TD]COL[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]Simon[/TD]
[TD]03/03/2018[/TD]
[TD]No[/TD]
[TD]REL[/TD]
[TD]COL[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]Rich[/TD]
[TD][/TD]
[TD]No[/TD]
[TD]AD[/TD]
[TD]SIM[/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]Darren[/TD]
[TD]05/06/2019[/TD]
[TD]No[/TD]
[TD]REL[/TD]
[TD]COL[/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]John[/TD]
[TD]01/04/2018[/TD]
[TD]No[/TD]
[TD]AD[/TD]
[TD]SIM[/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]Andrew[/TD]
[TD][/TD]
[TD]No[/TD]
[TD]REL[/TD]
[TD]SIM[/TD]
[/TR]
[TR]
[TD]9[/TD]
[TD]Oliver[/TD]
[TD][/TD]
[TD]Yes[/TD]
[TD]REL[/TD]
[TD]SIM
[/TD]
[/TR]
</tbody>[/TABLE]

So work on the assumption that the User ID's is Column A and so on. So the formulas I need will be going into Column G and beyond.

1st query. How many unique User ID’s are there with the following criteria – There is text in the Last Logon field and also the UTC is=”No”. So in this example the answer would be 3. This is User ID 1,5 & 8.
2nd query. As above but I now need to see how many unique User ID’s there are with the following criteria – The Last Logon field is blank and the UTC is =”No”. The important part with this one is that all of the same User ID’s must meet this requirement. So for instance User ID 1, Brian has not logged on and his UTC is “No”. But Gary and Stephen have logged on so this User id is not to be counted. So using this method the answer would be 2. This would be Rich and Steve.
3rd query. I need to count the total amount of User ID’s where at least 1 person has data in the Last logged on field and the UTC = “No”. This is not unique and I need a total. In this case it would be 5 (Gary, Stephen, John, Darren, Simon)
4th query. I need to count the total amount of User ID’s where at least 1 person has data in their Last Logon box and the UTC =”No”. This count needs to be User ID’s that are the same for instance John has met this criteria but we also need to include Andrew in the count because he has the same User ID. So in this scenario the count would be 7 (Gary, Stephen, Brian, Simon, Darren, John, Andrew)
4th query. I need to count the total amount of User ID’s where there is no data in the Last Logon Field and the UTC=”No”. This count needs to be similar to the 2nd query in that if there is a User ID that meets this requirement and another person with the same User ID does not meet the requirement then we need to disregard these users. So in this query the answer would be 2.
5th query. I need to count the how many Unique User ID’s there are that meet the following criteria – UTC=”No” –Model =”AD” Type=”SIM”. In this case the answer is 2 (Rich & John)
6th query. I need to count the total of User ID’s that meet the following criteria – UTC=”No” Model=”REL” Type=”COL”. In this case the answer is 5 (Stephen, Steve, Brian,Simon,Darren)
7th query. I need to count the total of User ID’s that meet this criteria – UTC=”No” Model=”REL” Type=”COL” and also where there is data in the Last Logon field. So in this scenario the count would be 3 (Stephen, Simon , Darren)

Thanks in advance.
 
M,

Is it possible to tweak the above formula to provide a list instead of just a number ? So say I put the formula in M1 it would list in M1, M2 etc,, the results of the query ?

Thanks

Maybe this..

[Table="class: grid"][tr][td="bgcolor: #DCE6F1"][/td][td="bgcolor: #DCE6F1"]
M
[/td][/tr]
[tr][td="bgcolor: #DCE6F1"]
1
[/td][td]
List​
[/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
2
[/td][td]
3​
[/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
3
[/td][td]
6​
[/td][/tr]

[tr][td="bgcolor: #DCE6F1"]
4
[/td][td][/td][/tr]
[/table]


Array formula in M2 copied down
=IFERROR(INDEX(A$2:A$14,SMALL(IF(FREQUENCY(IF(ISNA(MATCH(A$2:A$14,IF((C$2:C$14<>"")+(D$2:D$14="Yes"),A$2:A$14),0)),MATCH(A$2:A$14,A$2:A$14,0)),ROW(A$2:A$14)-ROW(A$2)+1),ROW(A$2:A$14)-ROW(A$2)+1),ROWS(M$2:M2))),"")
Ctrl+Shift+Enter

M.
 
Upvote 0

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Thanks M, works a treat. Is there a way of extending this out so M2 shows "3", N2 shows "Steve". The more info i can get here the better for my situation.

Thanks again.
 
Upvote 0
2nd query

Array formula
=SUM(IF(FREQUENCY(IF(ISNA(MATCH(A2:A14,IF((C2:C14<>"")+(D2:D14="Yes"),A2:A14),0)),MATCH(A2:A14,A2:A14,0)),ROW(A2:A14)-ROW(A2)+1),1))
Ctrl+Shift+Enter

Does it work for you?

M.

Hi M,

As you have done for one of my other formulas, can you assist with also getting these into a list instead of just a number ?

Thanks
 
Upvote 0
Thanks M, works a treat. Is there a way of extending this out so M2 shows "3", N2 shows "Steve". The more info i can get here the better for my situation.

Thanks again.

All you have to do is changing
=IFERROR(INDEX(A$2:A$14,...

to
=IFERROR(INDEX(B$2:B$14,...

M.
 
Upvote 0
Hi M,

As you have done for one of my other formulas, can you assist with also getting these into a list instead of just a number ?

Thanks

See formula in post 31 - same idea

Try to do it yourself - if you have problems come back here

M.
 
Upvote 0
Hi M,

Tried it but it's not right.

[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]=IFERROR(INDEX(A$2:A$14,SMALL(IF(FREQUENCY(IF(ISNA(MATCH($A$2:$A$14,IF(($C$2:$C$14<>"")+($D$2:$D$14="no"),$A$2:$A$14),0)),MATCH($A$2:$A$14,$A$2:$A$14,0)),ROW($A$2:$A$14)-ROW($A$2)+1),ROW(A$2:A$14)-ROW(A$2)+1),ROWS(N$2:N2))),"")

This gives me the User ID of 9 which is correct.

But

[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]=IFERROR(INDEX(B$2:B$14,SMALL(IF(FREQUENCY(IF(ISNA(MATCH($B$2:$B$14,IF(($C$2:$C$14<>"")+($D$2:$D$14="No"),$B$2:$B$14),0)),MATCH($B$2:$B$14,$B$2:$B$14,0)),ROW($B$2:$B$14)-ROW($B$2)+1),ROW(B$2:B$14)-ROW(B$2)+1),ROWS(N$2:N2))),"")

This gives me the name Trev but it should be Oliver as this is the name for User ID 9.

Any ideas what i'm doing wrong ?

Thanks[/FONT]<strike>
</strike>
[/FONT]
 
Upvote 0
Your formula seems perfect to me. Trev and Oliver satisfy the conditions.

M.
Hi M,

This isn't right.

One of the earlier formulas was the following :-

[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]=SUM(IF(FREQUENCY(IF(ISNA(MATCH(A2:A14,IF((C2:C14<>"")+(D2:D14="No"),A2:A14),0)),MATCH(A2:A14,A2:A14,0)),ROW(A2:A14)-ROW(A2)+1),1))

The result for this was 1. This is because there is 1 generic user ID where UTC=Yes and Last Logon is Blank. This is correct. Next I wanted a list of the results instead of a number.

This formula:-
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]=IFERROR(INDEX(A$2:A$14,SMALL(IF(FREQUENCY(IF(ISNA(MATCH($A$2:$A$14,IF(($C$2:$C$14<>"")+($D$2:$D$14="no"),$A$2:$A$14),0)),MATCH($A$2:$A$14,$A$2:$A$14,0)),ROW($A$2:$A$14)-ROW($A$2)+1),ROW(A$2:A$14)-ROW(A$2)+1),ROWS(N$2:N2))),"")

This gives me number 9 which is also correct as this is the user that meets the criteria on the above formula. What I tried to do with the following formula was pull the next cell to number 9 which was the name Oliver. However I get the name Trev instead but this person does not meet the criteria as their User ID is 4 and there is also another 4 that does not meet the criteria.

[/FONT][FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]=IFERROR(INDEX(B$2:B$14,SMALL(IF(FREQUENCY(IF(ISNA(MATCH($B$2:$B$14,IF(($C$2:$C$14<>"")+($D$2:$D$14="No"),$B$2:$B$14),0)),MATCH($B$2:$B$14,$B$2:$B$14,0)),ROW($B$2:$B$14)-ROW($B$2)+1),ROW(B$2:B$14)-ROW(B$2)+1),ROWS(O$2:O2))),"")

So Trev should never be part of this formula as there are 2 x User ID 4's and one does not meet the criteria.

Hope this makes sense.

Thanks as always.[/FONT]<strike>
</strike>
[/FONT]
 
Upvote 0
First
Array formula
=SUM(IF(FREQUENCY(IF($D$2:$D$14="NO",IF(E2:E14="REL",IF(F2:F14="COL",MATCH(A2:A14,A2:A14,0)))),ROW(A2:A14)-ROW(A2)+1),1))
Ctr+Shift+Enter

Second
Regular formula
=COUNTIFS(D2:D14,"No",E2:E14,"REL",F2:F14,"COL")

M.

Hi M,

How can I add another part to this formula so when it looks down E2:E14 it counts both Rel & AD ?

Thanks
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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