How to count only unique values from a column in a COUNTIFS

slam

Well-known Member
Joined
Sep 16, 2002
Messages
919
Office Version
  1. 365
  2. 2019
I have this formula so far:

Excel Formula:
=COUNTIFS(Raw!$B:$B,"11/22/2023  12:00:00 AM",Raw!S:S,A24,Raw!W:W,C23)

The problem is that my Raw worksheet has a lot of duplicates, and I only need to count one of each instance from column C on the Raw worksheet. Could someone please show me how to incorporate that into my formula?

Thanks!
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Hi,

maybe you could use COUNTA and FILTER instead..

I'm not exactly sure which data you want to count, and what values.. but here you see how to first filter your range for all your values, then choose UNIQUE items, then COUNT them

If you are filtering say Range B:W in total, then you add your three criteria in brackets, separated by "*" on each.
Then wrap inside UNIQUE()
Then use COUNTA to see how many results you have..

Excel Formula:
=COUNTA(UNIQUE(FILTER(B:W,(B:B="11/22/2023")*(S:S=A24)*(W:W=C23))))

Hope it helps guide you at least ..

ROb
 
Upvote 0
How about
Excel Formula:
=rows(unique(filter(Raw!$B:$B,(Raw!$B:$B="11/22/2023  12:00:00 AM")*(Raw!S:S=A24)*(Raw!W:W=C23))))
 
Upvote 0
Hi both - thank you for your replies. I have tried both solutions, but have some issues with each. I am not seeing either formula checking Raw!C:C to ensure the same value from this column is not counted twice. Apologies if I did not explain it well. Here is some more info that may help.

Column C is ID numbers

1234
1234
1234
1234
1234
5000
4444
4444
4444
4444
etc

On the Raw worksheet, the other columns I am referencing in the formula (B, S, W) are identical for each ID. If the other criteria matches what I'm looking for in my formula, I only want to increment the count by 1 for the ID 1234, regardless of how many times it appears.



Hi,

maybe you could use COUNTA and FILTER instead..

I'm not exactly sure which data you want to count, and what values.. but here you see how to first filter your range for all your values, then choose UNIQUE items, then COUNT them

If you are filtering say Range B:W in total, then you add your three criteria in brackets, separated by "*" on each.
Then wrap inside UNIQUE()
Then use COUNTA to see how many results you have..

Excel Formula:
=COUNTA(UNIQUE(FILTER(B:W,(B:B="11/22/2023")*(S:S=A24)*(W:W=C23))))

Hope it helps guide you at least ..

ROb
I've modified this formula to this to restore my sheet references, but the result is 1 for every cell I add it to, which should not be the case. Current formula:

Excel Formula:
=COUNTA(UNIQUE(FILTER(Raw!$B:$W,(Raw!$B:$B="11/22/2023")*(Raw!$S:$S=$A24)*(Raw!$W:$W=C$23))))

How about
Excel Formula:
=rows(unique(filter(Raw!$B:$B,(Raw!$B:$B="11/22/2023  12:00:00 AM")*(Raw!S:S=A24)*(Raw!W:W=C23))))

This is giving me a #CALC! error which says Empty Array
 
Upvote 0
Will try to get some sample data soon. Just a quick update to my explanation. I would look at it like it's almost like I did a Remove duplicates based on Raw!C:C before I used my formula in my first post. Then that formula would work as intended.
 
Upvote 0
Here is a simplified mock up with all other data removed, and how the output should look. The 2 in the second table needs to come from the formula. It should count each unique ID one time when the other criteria matches. This is Excel 365.

Unfortunately Mini Sheet is making my file crash, so using Table Only, and manually added in the column letters

ABCDEFGHIJKLMNOPQRSTUVW
BatchTimestampIDStatusOrg
11/22/2023 0:001341Carry OverCHI
11/22/2023 0:001341Carry OverCHI
11/22/2023 0:001341Carry OverCHI
11/22/2023 0:005000Carry OverCHI
11/22/2023 0:005000Carry OverCHI


CHI
Carry Over2


Thanks!
 
Upvote 0
Thanks for that, how about
Excel Formula:
=ROWS(UNIQUE(FILTER($B:$B,($B:$B=DATE(2023,11,22))*(S:S=S14)*(W:W=W14))))
 
Upvote 1
Solution
Hi Fluff, thank you, I've got this working. I think your first reference was intended to be C:C. I updated sheet references and gave it an IFERROR condition, because if there was no match, it was giving the CALC error. This is what I now have.

Excel Formula:
=IFERROR(ROWS(UNIQUE(FILTER(Raw!$C:$C,(Raw!$B:$B=DATE(2023,11,22))*(Raw!$S:$S=$A24)*(Raw!$W:$W=C$23)))),0)

Thank you again for all your incredible help!
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,869
Messages
6,175,088
Members
452,611
Latest member
bls2024

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