+ Reply to Thread
Results 1 to 15 of 15

Counting single zeros and consecutive zeros as one each

  1. #1
    Registered User
    Join Date
    10-31-2018
    Location
    Piedmont, mo
    MS-Off Ver
    Office Professioonal Plus 2016
    Posts
    8

    Counting single zeros and consecutive zeros as one each

    Hoping this hasn't already been covered here. I need a way to count zeros in a row, but I need to count single zeros as one and consecutive zeros as 1 also.

    So a row like this 0 1 0 0 1 1 would equal 2. Any help would be greatly appreciated.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Counting single zeros and consecutive zeros as one each

    a
    b
    c
    1
    2
    0
    4
    b2: {=sumproduct(--(frequency(if(a2:a13=0, row(a2:a13)), if(a2:a13<>0, row(a2:a13))) > 0))}
    3
    1
    4
    0
    5
    0
    6
    1
    7
    1
    8
    0
    9
    0
    10
    1
    11
    1
    12
    1
    13
    0
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    10-31-2018
    Location
    Piedmont, mo
    MS-Off Ver
    Office Professioonal Plus 2016
    Posts
    8

    Re: Counting single zeros and consecutive zeros as one each

    My data is arranged like this, but even when setup like you have yours I cannot get it to work.
    Attached Images Attached Images
    Last edited by rosstfer; 10-31-2018 at 05:41 PM.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Counting single zeros and consecutive zeros as one each

    A
    B
    C
    D
    E
    F
    G
    H
    I
    J
    K
    L
    M
    N
    1
    2
    0
    1
    0
    0
    1
    1
    0
    0
    1
    1
    1
    0
    3
    4
    4
    M4: {=SUMPRODUCT(--(FREQUENCY(IF(A2:L2=0, COLUMN(A2:L2)), IF(A2:L2<>0, COLUMN(A2:L2))) > 0))}


    The formula must be confirmed with Ctrl+Shift+Enter rather than just Enter. That's what makes the curly braces appear.

  5. #5
    Registered User
    Join Date
    10-31-2018
    Location
    Piedmont, mo
    MS-Off Ver
    Office Professioonal Plus 2016
    Posts
    8

    Re: Counting single zeros and consecutive zeros as one each

    Works perfect! Would it be possible to incorporate if there is a blank cell not to count it?

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Counting single zeros and consecutive zeros as one each

    =sumproduct(--(frequency(if(isnumber(a2:l2), if(a2:l2=0, column(a2:l2))), if(a2:l2=1, column(a2:l2))) > 0))

  7. #7
    Registered User
    Join Date
    10-31-2018
    Location
    Piedmont, mo
    MS-Off Ver
    Office Professioonal Plus 2016
    Posts
    8

    Re: Counting single zeros and consecutive zeros as one each

    Thank you so much for your help this is the final tweak I made =IF(SUMPRODUCT(--(FREQUENCY(IF(ISNUMBER(H2:K2), IF(H2:K2=0, COLUMN(H2:K2))), IF(H2:K2=1, COLUMN(H2:K2))) > 0))=0, "",SUMPRODUCT(--(FREQUENCY(IF(ISNUMBER(H2:K2), IF(H2:K2=0, COLUMN(H2:K2))), IF(H2:K2=1, COLUMN(H2:K2)))>0)))

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Counting single zeros and consecutive zeros as one each

    Or you could use the formula I posted and custom-format as 0;;
    Last edited by shg; 11-19-2018 at 02:25 PM.

  9. #9
    Registered User
    Join Date
    10-31-2018
    Location
    Piedmont, mo
    MS-Off Ver
    Office Professioonal Plus 2016
    Posts
    8

    Re: Counting single zeros and consecutive zeros as one each

    I have this connected to a pivot table and i think it would "count" everything?

  10. #10
    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
    44,063

    Re: Counting single zeros and consecutive zeros as one each

    Your final formula calculates twice...

    This is better:

    =IFERROR(1/(1/formula),"")

    where formula = the unduplicated formula you settled with.
    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

  11. #11
    Registered User
    Join Date
    10-31-2018
    Location
    Piedmont, mo
    MS-Off Ver
    Office Professioonal Plus 2016
    Posts
    8

    Re: Counting single zeros and consecutive zeros as one each

    Glenn Im not grasping what your showing me. Sorry its Monday

  12. #12
    Registered User
    Join Date
    10-31-2018
    Location
    Piedmont, mo
    MS-Off Ver
    Office Professioonal Plus 2016
    Posts
    8

    Re: Counting single zeros and consecutive zeros as one each

    ok I ran into a problem I reverted back to your formula but when I have a blank cell between a zero it is not counting it as two occurrences. Work perfect if there is a one between them.

  13. #13
    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
    44,063

    Re: Counting single zeros and consecutive zeros as one each

    =iferror(1/(1/IF(SUMPRODUCT(--(FREQUENCY(IF(ISNUMBER(H2:K2), IF(H2:K2=0, COLUMN(H2:K2))), IF(H2:K2=1, COLUMN(H2:K2))) > 0))=0),"")

    will only perform the calculation ONCE.

  14. #14
    Registered User
    Join Date
    10-31-2018
    Location
    Piedmont, mo
    MS-Off Ver
    Office Professioonal Plus 2016
    Posts
    8

    Re: Counting single zeros and consecutive zeros as one each

    Ok sorry to be so much trouble but I cannot get it to work so here is a snip of what I have
    0.0 represents a unexcused missed day
    blank represents a vacation day
    1.0 represents a day worked

    So in this scenario the formula should return a 2 and not a 1. As any group of missed days count as 1. But if a vacation day is between tow missed days it counts it as 1 when it should be a 2.Capture.PNG

  15. #15
    Forum Guru
    Join Date
    08-28-2014
    Location
    USA
    MS-Off Ver
    Excel 2019
    Posts
    17,570

    Re: Counting single zeros and consecutive zeros as one each

    Is it possible to add a number code for a vacation day? If 2.0 represented a vacation day (in cell C2) then the array entered formula (see post #4) could be modified to read:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Let us know if you have any questions.
    Consider taking the time to add to the reputation of everybody that has taken the time to respond to your query.

+ 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. Indicate the Instance of Consecutive Zeros in a Row
    By IbeforeV in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-04-2015, 04:27 PM
  2. [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
  3. Count longest consecutive run of zeros
    By TheRobsterUK in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-17-2013, 08:02 AM
  4. [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
  5. Counting consecutive zeros at end of range
    By darkyam in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 09-16-2010, 01:45 PM
  6. Excel Formula for Counting Consecutive Zeros
    By sheajm in forum Excel General
    Replies: 2
    Last Post: 12-27-2009, 08:45 AM
  7. Replies: 2
    Last Post: 09-22-2005, 08:05 AM

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