Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Putting a concatenate inside of a count if

Alright, I have two excel functions that work. I want to combine them into one. Here are the two that work:

=COUNTIF('ALL EE Active BEG PERIOD'!$A:$B, 'HC Summary Details'!$A6)

=CONCATENATE('ALL EE Active BEG PERIOD'!A2," --- ",'ALL EE Active BEG PERIOD'!B2)

I thought that maybe I could combine them as follows, but it's not working - where am I going wrong?

=COUNTIF(CONCATENATE('ALL EE Active BEG PERIOD'!A2,' --- ','ALL EE Active BEG PERIOD'!B2)),'HC Summary Details'!$A6)

like image 394
user1475816 Avatar asked Feb 01 '26 20:02

user1475816


2 Answers

The first part of a COUNTIF has to be a range, whereas you have a single text value with CONCATENATE... Unfortunately, it doesn't seem as if COUNTIF can handle arrays either, since I would have suggested =COUNTIF(CONCATENATE('ALL EE Active BEG PERIOD'!A:A,' --- ','ALL EE Active BEG PERIOD'!B:B)),'HC Summary Details'!$A6)

Anyway, there's another way of doing this, you can use SUMPRODUCT and and IF with CONCATENATE:

=SUMPRODUCT(IF(CONCATENATE('ALL EE Active BEG PERIOD'!A:A," --- ",'ALL EE Active BEG PERIOD'!B:B)='HC Summary Details'!$A6,1,0))

After you typed that, press Ctrl+Shift+Enter to get the desired result.

Pressing Enter alone will return you the value of the first term in the result array, which you don't want.

What this does is check whether the concatenate matches what is found in A6 of the other sheet, if yes, give 1, otherwise 0. SUMPRODUCT adds all the those 1 and 0 together.

like image 200
Jerry Avatar answered Feb 03 '26 10:02

Jerry


If you concatenate the range parameters into a string in another cell e.g. X1, and use COUNTIF(INDIRECT(X1),value) it seems that COUNTIF accepts the string as a range.

like image 25
Hugh Avatar answered Feb 03 '26 08:02

Hugh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!