Formula to count consecutive responses - text in two columns with response in one column

smide

Board Regular
Joined
Dec 20, 2015
Messages
162
Office Version
  1. 2016
Platform
  1. Windows
Hello.


In columns A and B (A2:A500 and B2:B500) I have a list of product names (text cells) and in column C (in the same row) their response.
Response in column C (C2:C500) is also text, a binary variable: Y (Yes) or N (No).


I need a formula to COUNT consecutive N (No) responses for each product's previous appearances and to place results in the columns D or E in the same row where referent product appears.
If referent product is in column A then result should be in column D and if referent product is in column B result should be placed in column E.


example.


Example only for Product1 here.

Sheet1 (stored data)

ABC
1Response
2Product1Product3Y
3Product2Product5N
4Product6Product1N
5Product3Product8N
6Product4Product1Y
7Product1Product6N
8Product2Product7Y
9Product1Product8N
10Product9Product1Y
11.........

<tbody>
</tbody>





Sheet1 (atfer calculation)

ABCDE
1ResponseResultResult
2Product1Product3Y
3Product2Product5N
4Product6Product1N0
5Product3Product8N
6Product4Product1Y1
7Product1Product6N0
8Product2Product7Y
9Product1Product8N1
10Product9Product1Y2
11...............

<tbody>
</tbody>


Calculation/counting explained (response Y - STOP counting!):


- E4 = 0 , previously Product1 appeared only in row2 (response Y)
- E6 = 1 , previously Product1 appeared in row4 (response N) and row2 (response Y)
- D7 = 0 , previously Product1 appeared in row6 (response Y)
- D9 = 1 , previously Product1 appeared in row7 (response N) and row6 (response Y)
- E10 = 2 , previously Product1 appeared in row9 (response N) and row7 (response N) and row6 (response Y)
 
Last edited:

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
@smide, what may look at first like a simple thing really isn't, but rather requires a lot of conditional logic and "last match" finagling.

That said, given your sample data set, enter the following formula into D2:

=IF(A2="Product1",IF(COUNTIF($A$2:$B2,"Product1")=1,"",IF(INDEX($C$1:$C1,SUMPRODUCT(MAX((($A$1:$A1="Product1")+($B$1:$B1="Product1"))*ROW($C$1:$C1))))="Y", 0,SUM(INDIRECT("D"&SUMPRODUCT(MAX((($A$1:$A1="Product1")+($B$1:$B1="Product1"))*ROW($C$1:$C1)))&":E"&ROW()-1))+1)),"")

Drag-copy the formula to E2. It will modify all relative references.

Then select D2 and E2, and drag-copy down Columns D and E.
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,279
Members
449,075
Latest member
staticfluids

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