+ Reply to Thread
Results 1 to 14 of 14

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

  1. #1
    Registered User
    Join Date
    08-20-2016
    Location
    Belgrade
    MS-Off Ver
    Windows 7 64-bit, Excel 2007
    Posts
    22

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

    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)

    A B C
    1 Response
    2 Product1 Product3 Y
    3 Product2 Product5 N
    4 Product6 Product1 N
    5 Product3 Product8 N
    6 Product4 Product1 Y
    7 Product1 Product6 N
    8 Product2 Product7 Y
    9 Product1 Product8 N
    10 Product9 Product1 Y
    11 ... ... ...

    Sheet1 (atfer calculation)

    A B C D E
    1 Response Result Result
    2 Product1 Product3 Y
    3 Product2 Product5 N
    4 Product6 Product1 N 0
    5 Product3 Product8 N
    6 Product4 Product1 Y 1
    7 Product1 Product6 N 0
    8 Product2 Product7 Y
    9 Product1 Product8 N 1
    10 Product9 Product1 Y 2
    11 ... ... ... ... ...

    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)

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,432

    Re: Formula to count consecutive responses - text in two columns with response in one colu

    What about all the other products? I don't understand what you are trying to do here - what is the data meant to show?
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Registered User
    Join Date
    08-20-2016
    Location
    Belgrade
    MS-Off Ver
    Windows 7 64-bit, Excel 2007
    Posts
    22

    Re: Formula to count consecutive responses - text in two columns with response in one colu

    Quote Originally Posted by AliGW View Post
    What about all the other products?
    Yes, I need 'counting' for ALL products. In example I calculated only for Product1 for simplicity.

    I don't understand what you are trying to do here - what is the data meant to show?
    Guess I'll have to wait for someone who do understand what I'm trying to do.
    Thanks for reply anyway.

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,432

    Re: Formula to count consecutive responses - text in two columns with response in one colu

    No, you will need to clarify your request!

    You say you need this counting for all products, so you need to show us what you really want. Where are the counts for others meant to go?

    What is the logic behind this?
    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)

  5. #5
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,148

    Re: Formula to count consecutive responses - text in two columns with response in one colu

    How many products as you will need 2 columns PER product ???? How will you know which response relates to which product?

    EDIT: maybe not !!! I see the "logic" now BUT I am uncertain whether this can be done via formulae.

    EDIT AGAIN: Taking your example, each formula in Column E has to relate to "Product1" until we exhaust all results for this product.

    We then have to repeat the exercise for "Product2", "Product6" etc .

    These set of tests will need to be in "product-unique" columns OR maybe use VBA for a two column solution.
    Last edited by JohnTopley; 07-15-2017 at 08:19 AM.

  6. #6
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    43,984

    Re: Formula to count consecutive responses - text in two columns with response in one colu

    I don't understand what you want either... I think...

    Maybe in D2:
    =IF(A2=$D$1,COUNTIF(A$2:A2,$D$1)-1,"")

    and in E2:
    =IF(B2=$D$1,COUNTIF(B$2:B2,$D$1)-1,"")
    Attached Files Attached Files
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

  7. #7
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,432

    Re: Formula to count consecutive responses - text in two columns with response in one colu

    EDIT: maybe not !!! I see the "logic" now.
    Do tell, JT!

  8. #8
    Registered User
    Join Date
    08-20-2016
    Location
    Belgrade
    MS-Off Ver
    Windows 7 64-bit, Excel 2007
    Posts
    22

    Re: Formula to count consecutive responses - text in two columns with response in one colu

    Quote Originally Posted by JohnTopley View Post
    How many products as you will need 2 columns PER product? How will you know which response relates to which product?
    Product from (lets say) row 4, Product 6 and Product 1 both have the same response N.

    If I wanted to calculate consecutive responses ONLY for Product1 I'll use this formula:
    =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)),"")

    I'll enter that formula into D2, then select D2 and E2 and finally drag-copy down Columns D and E.

    BUT.... I need one formula for (same counting) ALL products, not just for Product1 or any other single Product.
    So I guess it must be some array formula.
    Last edited by smide; 07-15-2017 at 08:16 AM.

  9. #9
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,432

    Re: Formula to count consecutive responses - text in two columns with response in one colu

    Please would you add your expected results for ALL products? Thanks.

  10. #10
    Registered User
    Join Date
    08-20-2016
    Location
    Belgrade
    MS-Off Ver
    Windows 7 64-bit, Excel 2007
    Posts
    22

    Re: Formula to count consecutive responses - text in two columns with response in one colu

    Quote Originally Posted by AliGW View Post
    Please would you add your expected results for ALL products? Thanks.
    Sheet1 (atfer calculation) - ALL products

    A B C D E
    1 Response Result Result
    2 Product1 Product3 Y 0 0
    3 Product2 Product5 N 0 0
    4 Product6 Product1 N 0 0
    5 Product3 Product8 N 0 0
    6 Product4 Product1 Y 0 1
    7 Product1 Product6 N 0 1
    8 Product2 Product7 Y 1 0
    9 Product1 Product8 N 1 1
    10 Product9 Product1 Y 0 2
    11 ... ... ... ... ...

  11. #11
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,148

    Re: Formula to count consecutive responses - text in two columns with response in one colu

    If you see Glenn's reply, then you will see the need for columns per product.

    See attached using OP's formula:
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    08-20-2016
    Location
    Belgrade
    MS-Off Ver
    Windows 7 64-bit, Excel 2007
    Posts
    22

    Re: Formula to count consecutive responses - text in two columns with response in one colu

    Quote Originally Posted by JohnTopley View Post

    We then have to repeat the exercise for "Product2", "Product6" etc .
    These set of tests will need to be in "product-unique" columns OR maybe use VBA for a two column solution.
    What do you think about using "R00C00" as some unique reference for all product's when counting?
    I mean something like: {=IFERROR(INDIRECT(TEXT(LARGE(IF($A$1:$B1=A2,ROW($A$1:$B1)*100+COLUMN($C$1:$D1)),3),"R00C00"),0)+...
    This is just an idea/formula example of course...

  13. #13
    Registered User
    Join Date
    08-20-2016
    Location
    Belgrade
    MS-Off Ver
    Windows 7 64-bit, Excel 2007
    Posts
    22

    Re: Formula to count consecutive responses - text in two columns with response in one colu

    Quote Originally Posted by JohnTopley View Post
    If you see Glenn's reply, then you will see the need for columns per product.

    See attached using OP's formula:
    Unfortunately I can not allow in my project additional columns, columns per product etc.
    However I really appreciate your effort. Thank you.

  14. #14
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,148

    Re: Formula to count consecutive responses - text in two columns with response in one colu

    If you don't find a formula solution, then it would be possible to create a VBA macro which would loop through products and assign (change) the product referenced in the formula so would still have your 2 columns.

    If VBA is acceptable, ask a moderator to re-assign this thread to the VBA/Macro forum.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Count consecutive text values that can vary
    By dmartin72724 in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 05-11-2016, 11:28 AM
  2. Replies: 2
    Last Post: 04-13-2015, 08:32 PM
  3. Formula that will count response days with conditions
    By zince14 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-13-2013, 12:13 AM
  4. [SOLVED] Count consecutive cells with certain text
    By moppyau in forum Excel Formulas & Functions
    Replies: 19
    Last Post: 04-30-2013, 09:35 AM
  5. [SOLVED] How to count consecutive columns
    By adrianplunkett in forum Excel General
    Replies: 13
    Last Post: 05-21-2012, 10:02 AM
  6. Replies: 2
    Last Post: 05-16-2011, 10:13 AM
  7. Count non consecutive columns
    By [email protected] in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 05-23-2006, 10:30 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1