How to use COUNTIF and FREQUENCY in combination?

khavusr

New Member
Joined
Mar 10, 2016
Messages
8
Office Version
  1. 2021
Platform
  1. Windows
I'm currently using this formula to count the frequency words used in Columns:

=SUM(IF(FREQUENCY(IF(LEN(G2:G100)>0;MATCH(G2:G100;G2:G100;0);""); IF(LEN(G2:G100)>0;MATCH(G2:G100;G2:G100;0);""))>0;1))

But, would like to include COUNTIF to only count the frequency if it also matches and additional phrase in another Column; so the pre-check should be using:

=COUNTIF(E2:E100; "Country")

How would the above play out adding the COUNTIF to frequency sum formula above; currently banging my head and end up with formula error and it's structure error but getting kind of blind on this one by now:

=COUNTIF((E2:E100; "Country"); (IF(FREQUENCY(IF(LEN(G2:G100)>0;MATCH(G2:G100G2:G100;0);""); IF(LEN(G2:G100)>0;MATCH(G2:G100;G2:G100;0);""))>0;1)))
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
The 2 don't go really go together, it's always better to explain in words (preferably with a sample using XL2BB, not screen captures or copy and paste).

Maybe this, array confirmed?

=SUMPRODUCT(IFERROR(1/COUNTIFS(G2:G100;G2:G100&"";E2:E100;E2:E100,E2:E100;"Country");0))
 
Upvote 0
Thanks for the input Jason. What I'm trying to do is to count the numbers of countries linked to a specific department. So in this below example Dep1 has 4 different countries linked (United Kingdom, Unites States, Sweden and France) and Dep2 has 1 country linked (Germany). So the Country value should only be counted once for each Department. Hope this makes it a bit more clear what I'm trying to do and guess that I over complicated with my own efforts :)

Country:Department
United KingdomDep1
United StatesDep1
SwedenDep1
GermanyDep2
United KingdomDep1
FranceDep1
 
Upvote 0
You mean like this?

Book1
ABCDE
1Country:Department
2United KingdomDep1Dep14
3United StatesDep1Dep21
4SwedenDep1
5GermanyDep2
6United KingdomDep1
7FranceDep1
Sheet4
Cell Formulas
RangeFormula
E2:E3E2=SUMPRODUCT(IFERROR(1/COUNTIFS(A2:A100,A2:A100&"",B2:B100,B2:B100,B2:B100,D2),0))
Press CTRL+SHIFT+ENTER to enter array formulas surrounded with curly braces.
 
Upvote 0
Yes, the above did the trick for what I needed. How do I avoid having this formula to include empty cells as value? Meaning if you in the above example had an additional Row 8 where A8 would be empty and B8 says Dep1 then the B8 would increase the value in E2 to 5; so it's counting the empty cell as a valid entry. How is this avoided?
 
Upvote 0
If they are truly empty then

=SUMPRODUCT(IFERROR(1/COUNTIFS(A2:A100,A2:A100,B2:B100,B2:B100,B2:B100,D2),0))

If they are blank (look empty but contain a formula) then I'll take another look at frequency.
 
Upvote 0
Ah, Missed the &"" and with this removed it works out fine. Ok, the SUMPRODUCT makes better sense now. Good Stuff!
 
Upvote 0

Forum statistics

Threads
1,215,756
Messages
6,126,692
Members
449,330
Latest member
ThatGuyCap

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