SUMPRODUCT/COUNTIF looking at whether a value is in one of several cells in a row

biomathics23

New Member
Joined
Sep 10, 2018
Messages
6
Hello and thanks for reading,

I have a setup similar to the following (but much larger), featuring a single column containing names (each cell in this column will have a name), and several columns whose cells may contain letters (though many do not). Each name is unique but more than one letter may appear in a single cell as follows:


RowNamesLetters1Letters2Letters3Letters4
1YanniA,BAA, C
2Zane
3
XerxesBA, B
4YanniCC
5YanniA
6XerxesB,C
7ZaneABC

<tbody>
</tbody>

I am trying to find a formula that captures the following notion: Given Xerxes and A, how many rows have a "1" in the Numbers column and also have at least one "A" somewhere in Letters1-4 columns? So for Xerxes and A, only row 3 satisfies that, so the formula should return "1". For Yanni and A, rows 1 and 5 work, so the formula should return "2", etc.

I would like to use this formula to then populate a grid like the one below (results shown are based on the above example):

ABC
Xerxes121
Yanni212
Zane111

<tbody>
</tbody>

I tried to manipulate the sumproduct and countifs functions in a variety of ways, but I could never figure out how to get it to look at several cells (in actuality 10+) in a single row for a given letter while still summing over all the rows. The only solution I could think of would be to add a helper column of concatenated columns Letters1-4, and then sumproduct or countifs with that helper column and the name column, but I would vastly prefer avoiding such a workaround.

Any thoughts/advice/solutions?
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Hi,

I don't see a "Numbers" Column where you say the 1 should be?
 
Upvote 0
My apologies, I edited the post but apparently missed some parts. That should have been "Names" column and "Xerxes", not "Numbers" and "1". Since it is too late to edit here is how it should have read:



Hello and thanks for reading,

I have a setup similar to the following (but much larger), featuring a single column containing names (each cell in this column will have a name), and several columns whose cells may contain letters (though many do not). Each name is unique but more than one letter may appear in a single cell as follows:


RowNamesLetters1Letters2Letters3Letters4
1YanniA,BAA, C
2Zane
3XerxesBA, B
4YanniCC
5YanniA
6XerxesB,C
7ZaneABC

<tbody>
</tbody>


I am trying to find a formula that captures the following notion: Given Xerxes and A, how many rows have "Xerxes" in the Names column and also have at least one "A" somewhere in Letters1-4 columns? So for Xerxes and A, only row 3 satisfies that, so the formula should return "1". For Yanni and A, rows 1 and 5 work, so the formula should return "2", etc.

I would like to use this formula to then populate a grid like the one below (results shown are based on the above example):

ABC
Xerxes121
Yanni212
Zane111

<tbody>
</tbody>


I tried to manipulate the sumproduct and countifs functions in a variety of ways, but I could never figure out how to get it to look at several cells (in actuality 10+) in a single row for a given letter while still summing over all the rows. The only solution I could think of would be to add a helper column of concatenated columns Letters1-4, and then sumproduct or countifs with that helper column and the name column, but I would vastly prefer avoiding such a workaround.

Any thoughts/advice/solutions?
 
Upvote 0
So this formula does not use sumproduct or countifs, but it works: (This assumes the cell containing the word "Row" is A1)

=MMULT(--(TRANSPOSE($B$2:$B$8=$G13)),N(MMULT(N(ISNUMBER(SEARCH(J$12,$C$2:$F$8))),TRANSPOSE(COLUMN($C$2:$F$8)^0))>0))

Basically it acts like sumproduct on steriods.

Let me know if you have any questions or concerns.
 
Upvote 0
My apologies, I edited the post but apparently missed some parts. That should have been "Names" column and "Xerxes", not "Numbers" and "1".

No problem, just needed to know if That was another requirement for the formula(s).

You can either do a SUM/COUNTIFS or a SUMPRODUCT, I'm showing the SUMPRODUCT as the SUM/COUNTIFS is a much longer formula and in case you have additional Letters Columns in the future:

One important note, your sample results seems incorrect.


Book1
ABCDE
1NamesLetters1Letters2Letters3Letters4
2YanniA,BAA, C
3Zane
4XerxesBA, B
5YanniCC
6YanniA
7XerxesB,C
8ZaneABC
9
10
11ABC
12Xerxes131
13Yanni413
14Zane111
Sheet402
Cell Formulas
RangeFormula
B12=SUMPRODUCT(($A$2:$A$8=$A12)*(ISNUMBER(SEARCH(B$11,$B$2:$E$8))))


B12 formula copied down and across to D14
 
Upvote 0
ExcelElliott: Steroids indeed! That formula does just what I wanted, though I will have to go through the different functions to try to understand how it actually works. Thanks so much!

jtakw: I tried that approach but got the same results you did, which are not what I wanted: your formula gets 3 for Xerxes and B, because it counts the two B's in row 4 separately. I just wanted to count each row once, regardless of if it had 1 B or multiple B's. I do not think sumproduct can get there (do correct me if I am wrong), but thanks for the suggestion.
 
Upvote 0
A bit shorter...


Book1
ABCDEFGHIJK
1NamesLetters1Letters2Letters3Letters4ABC
2YanniA,BAA, CXerxes121
3ZaneYanni212
4XerxesBA, BZane111
5YanniCC
6YanniA
7XerxesB,C
8ZaneABC
Sheet1


In I2 control+shift+enter, not just enter, copy across, and down:

=SUMPRODUCT(($A$2:$A$8=$H2)+0,(MMULT(ISNUMBER(SEARCH(I$1,$B$2:$E$8))+0,TRANSPOSE(COLUMN($B$2:$E$8)^0))>0)+0)

Note. It's the TRANSPOSE call that necessitates applyin control+shift+enter in this formula with SUMPRODUCT.
 
Upvote 0
jtakw: I tried that approach but got the same results you did, which are not what I wanted: your formula gets 3 for Xerxes and B, because it counts the two B's in row 4 separately. I just wanted to count each row once, regardless of if it had 1 B or multiple B's. I do not think sumproduct can get there (do correct me if I am wrong), but thanks for the suggestion.

Sorry, I misunderstood your question...
 
Upvote 0

Forum statistics

Threads
1,214,588
Messages
6,120,409
Members
448,959
Latest member
camelliaCase

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