+ Reply to Thread
Results 1 to 11 of 11

How to count the amount of zeros on a line and between two consecutive 1

  1. #1
    Registered User
    Join Date
    05-06-2021
    Location
    Stavanger
    MS-Off Ver
    Microsoft 365
    Posts
    7

    How to count the amount of zeros on a line and between two consecutive 1

    I would like to have some help regarding a formula that I can use to determine the amount of zeros between two consecutive 1.

    Consider following example: 34 columns of which seven are 1 and the rest zeroes:
    0 1 0 1 0 0 1 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0

    1 1 2 8 1 6 1 7

    - There is one zero before the first 1.
    - There is one zero between the first and the second 1
    - There are two zeroes between the second and the third 1
    - There are eight zeroes between the third and the fourth 1
    .
    .
    .
    There is one zero between the sixth and the seventh 1
    - There are seven zeroes after the seventh/last 1

    The answer I am looking for is then:
    1 1 2 8 1 6 1 7

    Imagine that there are over 300 lines (see attached excel file)...it will take ages to do the counting manually...

    Is there a formula that I can use to get the result?

    Bambynor
    Attached Files Attached Files

  2. #2
    Forum Expert XLent's Avatar
    Join Date
    10-13-2010
    Location
    Northumberland, UK
    MS-Off Ver
    various
    Posts
    2,704

    Re: How to count the amount of zeros on a line and between two consecutive 1

    do you mean:

    AJ1: =TRIM(SUBSTITUTE(TEXTJOIN(" ";;" ";FREQUENCY(IF(NOT(B1:AI1);COLUMN(B1:AI1));IF(B1:AI1;COLUMN(B1:AI1)));" ");" 0";""))
    copied down

    above would return "1 1 2 8 1 6 1 7"

  3. #3
    Registered User
    Join Date
    05-06-2021
    Location
    Stavanger
    MS-Off Ver
    Microsoft 365
    Posts
    7

    Re: How to count the amount of zeros on a line and between two consecutive 1

    Thank you XLent. Is it possible to get the answer split in eight cells:
    AJ - 1
    AK - 1
    AL- 2
    AM - 8
    AN - 1
    AO - 6
    AP - 1
    AQ - 7
    I ask this because I would like to have statistically the minimum an maximum for each of the eight variables.
    Bambynor

  4. #4
    Forum Expert XLent's Avatar
    Join Date
    10-13-2010
    Location
    Northumberland, UK
    MS-Off Ver
    various
    Posts
    2,704

    Re: How to count the amount of zeros on a line and between two consecutive 1

    so, given O365, you could perhaps use something like:

    AJ1: =IFERROR(MID(TEXTJOIN(" ";;TEXT(FREQUENCY(IF(NOT($B2:$AI2);COLUMN($B2:$AI2));IF($B2:$AI2;COLUMN($B2:$AI2)));"[=0]"""";00"));1+3*(COLUMN(B2:AI2)-COLUMN(B2));2)+0;"")
    copied down (should spill across)

    I've attached a working version of the same in case the above does not translate correctly for your locale (albeit the above is in AL1 rather than AJ1, as AJ1 holds the earlier string example)
    Attached Files Attached Files
    Last edited by XLent; 05-06-2021 at 06:50 AM. Reason: typo in narrative

  5. #5
    Registered User
    Join Date
    05-06-2021
    Location
    Stavanger
    MS-Off Ver
    Microsoft 365
    Posts
    7

    Re: How to count the amount of zeros on a line and between two consecutive 1

    Wow!
    I am impressed...thank you very much for the help.

    Bambynor

  6. #6
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,211

    Re: How to count the amount of zeros on a line and between two consecutive 1

    Please try

    =TRANSPOSE(LEN(FILTERXML("<x><m>"&SUBSTITUTE(CONCAT(1-B1:AI1);0;"</m><m>")&"</m></x>";"//m[.>0]")))
    Attached Files Attached Files

  7. #7
    Forum Expert XLent's Avatar
    Join Date
    10-13-2010
    Location
    Northumberland, UK
    MS-Off Ver
    various
    Posts
    2,704

    Re: How to count the amount of zeros on a line and between two consecutive 1

    VERY nice @Bo_Ry !

  8. #8
    Registered User
    Join Date
    05-06-2021
    Location
    Stavanger
    MS-Off Ver
    Microsoft 365
    Posts
    7

    Re: How to count the amount of zeros on a line and between two consecutive 1

    There is one more thing:
    The formula proposed give following result:

    0 1 0 1 0 0 1 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 -RESULT- 1 1 2 8 1 6 1 7 - CORRECT

    1 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 -RESULT- 11 5 1 10
    In my opinion the correct result is: 0 0 11 5 0 0 1 10
    There are no zeroes before the first 0, there are no zeroes between the first and the second 1 - that explains the 0 0 at the start. Between the fourth, the fifth and the sixth 1 there are no zeroes in which case the result should have two zeroes between 5 and 1.
    Any chance to modify the formula (the last one proposed that gives the result split in eight columns)?
    Bambynor

  9. #9
    Registered User
    Join Date
    05-06-2021
    Location
    Stavanger
    MS-Off Ver
    Microsoft 365
    Posts
    7

    Re: How to count the amount of zeros on a line and between two consecutive 1

    There is one more thing:
    The formula proposed give following result:

    0 1 0 1 0 0 1 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 -RESULT- 1 1 2 8 1 6 1 7 - CORRECT

    1 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 -RESULT- 11 5 1 10
    In my opinion the correct result is: 0 0 11 5 0 0 1 10
    There are no zeroes before the first 0, there are no zeroes between the first and the second 1 - that explains the 0 0 at the start. Between the fourth, the fifth and the sixth 1 there are no zeroes in which case the result should have two zeroes between 5 and 1.

    1 0 0 0 1 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1
    The result should be: 0 3 1 6 11 6 0

    Any chance to modify the formula (the last one proposed that gives the result split in eight columns)?
    Bambynor
    Last edited by Bambynor; 05-06-2021 at 07:59 AM.

  10. #10
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,211

    Re: How to count the amount of zeros on a line and between two consecutive 1

    Thanks, Luke.


    the correct result is: 0 0 11 5 0 0 1 10
    Please try
    =TRANSPOSE(LEN(FILTERXML("<x><m>1"&SUBSTITUTE(CONCAT(1-B1:AI1);0;"</m><m>1")&"</m></x>";"//m"))-1)

  11. #11
    Registered User
    Join Date
    05-06-2021
    Location
    Stavanger
    MS-Off Ver
    Microsoft 365
    Posts
    7

    Re: How to count the amount of zeros on a line and between two consecutive 1

    EXCELLENT!!
    This is amazing...
    Thank you very much.

    Bambynor

+ 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. [SOLVED] How to count the amount of times there are 7 consecutive 1s or 0s in cells down a column
    By Salmonbushes in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 6
    Last Post: 12-30-2020, 10:04 AM
  2. Replies: 2
    Last Post: 12-30-2020, 08:40 AM
  3. [SOLVED] Count Max Consecutive Zeros
    By Feastie in forum Excel General
    Replies: 5
    Last Post: 07-07-2020, 06:38 AM
  4. Count the amount of consecutive dates
    By zuprex in forum Excel General
    Replies: 2
    Last Post: 02-09-2017, 01:39 PM
  5. [SOLVED] Count of Consecutive Zeros excluding #N/A
    By gaffee in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 07-10-2014, 10:04 AM
  6. Count longest consecutive run of zeros
    By TheRobsterUK in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-17-2013, 08:02 AM
  7. [SOLVED] Average for non-consecutive cells excluding zeros (even when they all contain zeros)
    By pao13 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-05-2012, 04:32 PM

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