Counting Unique Cells based on 2 values in other columns

ultracyclist

Active Member
Joined
Oct 6, 2010
Messages
271
Office Version
  1. 365
Platform
  1. Windows
Hi,

I need help with a formula. I’m counting unique cells in Column B and want to add criteria that looks column J for the value of 21 and Column K for Hardware. If both criteria match the unique value, it will count.

Here’s two formulas that I’ve tried with no luck

=COUNTA(UNIQUE(B16:B972,$J:$SJ="21","*Hardware*",K:K))

=SumIF (Unique(B2:B900),($J:$J='21'),($K:$K='Hardware')

Network Budget-SDWAN-Meraki-11-1-Master Final.xlsx
BCDEFGHIJK
1Site CodePurchase YearCost Type
2COLB21Hardware
3COLB21Software
4COLB
5COLB
6COLB
7COLB
8COLI21Hardware
9COLI21Software
10COLI
11PITA21Hardware
12PITA21Software
13PITA
14PITA
15LOED21Hardware
16LOED21Software
17LOED
US Switch Replacements(Master)
Cells with Data Validation
CellAllowCriteria
J1List=$Q$2:$Q$3
J2:J17List=$O$2:$O$7
 
try Power Query (Get&Transform)
Site CodePurchase YearCost TypeCount
COLB21Hardware4
COLB21Software
COLB
COLB
COLB
COLB
COLI21Hardware
COLI21Software
COLI
PITA21Hardware
PITA21Software
PITA
PITA
LOED21Hardware
LOED21Software
LOED

Power Query:
// Count
let
    Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
    NoNull = Table.SelectRows(Source, each [Purchase Year] = 21),
    Hardware = Table.SelectRows(NoNull, each ([Cost Type] = "Hardware")),
    Count = Table.RowCount(Hardware)
in
    Count
 
Upvote 0

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Does this do what you want?

20 11 02.xlsm
BJKLM
1Site CodePurchase YearCost TypeCount
2COLB21Hardware4
3COLB21Software
4COLB
5COLB
6COLB
7COLB
8COLI21Hardware
9COLI21Software
10COLI
11PITA21Hardware
12PITA21Software
13PITA
14PITA
15LOED21Hardware
16LOED21Software
17LOED
Count Unique
Cell Formulas
RangeFormula
M2M2=ROWS(UNIQUE(FILTER(B2:B17,(J2:J17=21)*(K2:K17="Hardware"))))
 
Upvote 0
or with you example
Book1
BCDEF
1Site CodePurchase YearCost Type
2COLB21Hardware
3COLB21Software
4COLB
5COLB
6COLB
7COLB
8COLI21Hardware
9COLI21Software
10COLI
11PITA21Hardware
12PITA21Software
13PITA
14PITA
15LOED21Hardware
16LOED21Software
17LOED4
Sheet4
Cell Formulas
RangeFormula
F17F17=SUMPRODUCT((Table3[Purchase Year]=21)*(Table3[Cost Type]="Hardware"))
 
Upvote 0
or with you example

Not sure which example you are referring to as I don't see any tables with that data in columns B:D

In any case there is nothing in that SUMPRODUCT formula that assures a count of unique values as appears to be requested going by the thread title and the attempted formulas. It just happens that in the sample given, the Site Code values were unique for 21 & hardware but try changing your cell D3 to "Hardware".
 
Upvote 0
or just use PivotTable
ptdistinct.png


fields.png
 
Last edited:
Upvote 0
Peter,

I tried copying your formula to my sheet, but it pops up a dialog box that says "That function is not valid" Its perplexing me that I cannot figure a way to capture the information as shown in your example. I appreciate the help. Worst case I create some filters in my sheet instead of trying to use a formula.
 
Upvote 0
it pops up a dialog box that says "That function is not valid"
Since you were using the UNIQUE function in post 1, I assumed that your Excel 365 had that function and the therefore also the FILTER function but perhaps you do not have them? Can you check each one like this?

If you click the fx button and choose 'Lookup & Reference' is FILTER in the list?
1604285797877.png
 
Upvote 0
that is why I said "with your example"
If we took your example as representative then since every "Hardware" has 21 and a unique Site code, all you would need would be this. ;)
=COUNTIF(Table3[Cost Type],"Hardware").
 
Upvote 0

Forum statistics

Threads
1,215,992
Messages
6,128,170
Members
449,429
Latest member
ianharper68

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