+ Reply to Thread
Results 1 to 20 of 20

counting consecutive days of loss while ignoring zero values

  1. #1
    Registered User
    Join Date
    01-16-2018
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    11

    counting consecutive days of loss while ignoring zero values

    Hello,

    I am looking for a formula that will count consecutive cells of negative numbers in one column while ignoring zero values....please help!

    Thank you!

  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,398

    Re: counting consecutive days of loss while ignoring zero values

    Welcome to the forum!

    You need to use the COUNTIF function and set the criterion to less than 0.
    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
    Forum Expert
    Join Date
    10-02-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    1,222

    Re: counting consecutive days of loss while ignoring zero values

    Can you post a sample of your data.

    COUNTIF will do it for you only if you want to count all of the cells that meet your criteria in a range. Your question specifically stats "consecutive" which complicates matters beyond a simple COUNTIF. So do you actually mean counting consecutive according to some criteria within the column or where you just stating that your data set as a whole is consecutive?
    Ways to get help: Post clear questions, explain your overall goal, supply as much background as possible, respond to questions asked of you by those trying to help and post sample(s) files.

    "I am here to help, not do it for people" -Me

  4. #4
    Registered User
    Join Date
    01-16-2018
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    11

    Re: counting consecutive days of loss while ignoring zero values

    Hello,

    I am trying to count the consecutive days of loss but the complicated part are the zero values for weekends where data is not entered. In the example below, I have five consecutive days of loss, but all formulas I try return a value of 4.

    14,677
    (12,872)
    (40)
    (29)
    (18)
    -
    -
    (55)
    26
    37
    48

  5. #5
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: counting consecutive days of loss while ignoring zero values

    Try array entering this formula in C1 as below. If you aren’t familiar with array-entered formulas array enter means the formula must be committed from edit mode by simultaneously pressing and holding down Ctrl and Shift while hitting Enter.

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    A little comment might be in order here. In order to make it work this formula "re-purposes" the Holidays argument of NETWORKDAYS to be the days corresponding with amounts < 0.


    A
    B
    C
    D
    1
    1/8/2018
    14,677
    5
    In C1: {=SUM(IF(NETWORKDAYS(WORKDAY(A1-1,ROW(1:11)),WORKDAY(A1-1,ROW(1:11)),N(IF(1,IF(B1:B11<0,A1:A11))))=0,1))}
    2
    1/9/2018
    -12,872
    3
    1/10/2018
    -40
    4
    1/11/2018
    -29
    5
    1/12/2018
    -18
    6
    1/13/2018
    0
    7
    1/14/2018
    0
    8
    1/15/2018
    -55
    9
    1/16/2018
    26
    10
    1/17/2018
    37
    11
    1/18/2018
    48
    Dave

  6. #6
    Registered User
    Join Date
    01-16-2018
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    11

    Re: counting consecutive days of loss while ignoring zero values

    Thank you, I tried this and it came back with an error in the formula, could it be this part...,ROW(1:11)),N(IF(1, (I'm not sure what the "N" is for?)

  7. #7
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: counting consecutive days of loss while ignoring zero values

    Did you enter it as an array formula? ie as Flame said by holding down Ctrl+Shift then pressing enter.

    So you type in your formula then hold Ctrl+Shift and press enter, you should see the formula surrounded by { and }
    If someone has helped you then please add to their Reputation

  8. #8
    Registered User
    Join Date
    01-16-2018
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    11

    Re: counting consecutive days of loss while ignoring zero values

    Yes, I did, it shows an error in the formula.

  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,398

    Re: counting consecutive days of loss while ignoring zero values

    What error message do you get?

  10. #10
    Registered User
    Join Date
    01-16-2018
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    11

    Re: counting consecutive days of loss while ignoring zero values

    It simply states there is an error in the formula....I am thinking it is related to the "N" as I believe there is something missing there

  11. #11
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: counting consecutive days of loss while ignoring zero values

    The "N" is an Excel function. With "IF(1" nested inside it coerces the array "IF(B1:B11<0,A1:A11)". Occasionally this is a necessary step in some array formulas. Range and array coercion are very common issues among the dating functions and WORKDAY is one of those functions.

    Are you committing the formula from edit mode with Ctrl + Shift + Enter ... instead of with just Enter?

    See the attached. With C1 the active cell note the {} curly braces around the formula in the formula bar. You don't type those in yourself. I you do you will get an error. Excel puts those there when you commit with Ctrl + Shift + Enter.
    Last edited by FlameRetired; 01-17-2018 at 02:47 PM. Reason: re-wording

  12. #12
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: counting consecutive days of loss while ignoring zero values

    By-the-way upon further review this formula returns 5 and is simpler in this case.
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  13. #13
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: counting consecutive days of loss while ignoring zero values

    Upon more further review it occurs to me neither of those formulas will do what you want. For example if -55 were on a Tuesday I am guessing you would expect the return to be 4. These both still return 5.

    This formula will return the count of contiguous non-weekend days of < 0 in column B. It is also array entered, but is limited to returning the count of only one contiguous "run". Somehow I suspect there is more to the problem than this. Is that correct?

    Array entered.
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  14. #14
    Forum Expert
    Join Date
    10-02-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    1,222

    Re: counting consecutive days of loss while ignoring zero values

    I may be able to adjust the formula from this post to accomplish what you want. Ill give it a shot and if all goes well post back here.

    Is it possible for there to be multiple consecutive sets of negatives/zero's?

    ie:
    2
    4
    -5
    -2
    -3
    0
    -1
    6
    7
    -3
    -3
    2

    If the above is possible, what do you want to return? Longest consecutive set?

    Presuming the above is possible (should still work regardless, but if its only 1 consecutive range it can be done much easier) this should do it. I added to the sample posted by FlameRetired to have multiple consecutive ranges of varying frequency. Seems to get it correct (array entered)

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    See attached
    Last edited by Zer0Cool; 01-17-2018 at 11:45 PM.

  15. #15
    Registered User
    Join Date
    01-16-2018
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    11

    Re: counting consecutive days of loss while ignoring zero values

    For some reason I am not able to open the attachments?!

    There can be multiple, consecutive sets of negative numbers, the return I am looking for is, if there are 5 consecutive days of loss in column H (Inventory Variance), I simply need it to return a "yes" see below :




    Closing Inventory
    Day Opening Purchases Cardlock Total Book Physical Variance
    Inventory Sales Sales Inventory Inventory (+/-)
    1-Jan-18 12 50 1,918 1,918 (1,856) 12,821 14,677
    2-Jan-18 12,821 51 (1) (1) 12,873 1 (12,872)
    3-Jan-18 1 52 11 11 42 2 (40)
    4-Jan-18 2 53 23 23 32 3 (29)
    5-Jan-18 3 54 35 35 22 4 (18)
    6-Jan-18 4 - - - 4 5 -
    7-Jan-18 5 - - - 5 6 -
    8-Jan-18 6 57 1 1 62 7 (55)
    9-Jan-18 7 58 83 83 (18) 8 26
    10-Jan-18 8 59 95 95 (28) 9 37

  16. #16
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: counting consecutive days of loss while ignoring zero values

    leslieann they upload and open fine at my end. What message(s) pop up when you try?

    I don't understand your latest data layout. It is not the same as post #4. There are multiple negative figures each day. Please post an example of expected results. Better yet please upload a workbook with a BEFORE section of data source and layout and an AFTER section of results including layout. The mission is becoming less clear to me.

    If you are not familiar with how to do this (save yourself some grief ... the "paperclip" icon has not worked for some time):


    To attach a file to your post,
    • be sure to desensitize the data
    • click “Go Advanced” (next to Post Quick Reply – bottom right),
    • scroll down until you see “Manage Attachments”, click that,
    • click “Browse”.
    • select your file(s)
    • click “Upload”
    • click “Close window”
    • click “Submit Reply”

    The file name will appear at the bottom of your reply.

  17. #17
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: counting consecutive days of loss while ignoring zero values

    In the meantime I took a guess at what you wanted.

    Array entered in B1 and filled across.
    Formula: copy to clipboard
    Please Login or Register  to view this content.



    A
    B
    C
    D
    E
    F
    G
    H
    I
    1
    0
    0
    1
    1
    2
    0
    5
    2
    1-Jan-18
    12
    50
    1,918
    1,918
    (1,856)
    12,821
    14,677
    Workday
    3
    2-Jan-18
    12,821
    51
    (1)
    (1)
    12,873
    1
    (12,872)
    Workday
    4
    3-Jan-18
    1
    52
    11
    11
    42
    2
    (40)
    Workday
    5
    4-Jan-18
    2
    53
    23
    23
    32
    3
    (29)
    Workday
    6
    5-Jan-18
    3
    54
    35
    35
    22
    4
    (18)
    Workday
    7
    6-Jan-18
    4
    -
    -
    -
    4
    5
    -
    Weekend
    8
    7-Jan-18
    5
    -
    -
    -
    5
    6
    -
    Weekend
    9
    8-Jan-18
    6
    57
    1
    1
    62
    7
    (55)
    Workday
    10
    9-Jan-18
    7
    58
    83
    83
    (18)
    8
    26
    Workday
    11
    10-Jan-18
    8
    59
    95
    95
    (28)
    9
    37
    Workday

  18. #18
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: counting consecutive days of loss while ignoring zero values

    Quote Originally Posted by Zer0Cool View Post
    =MAX(FREQUENCY(IF($B$1:$B$24<=0,ROW($B$1:$B$24)),IF($B$1:$B$24>0,ROW($B$1:$B$24))))
    This get's a result of 7 for the example given because it also counts the two zeroes. My understanding is that the zeroes should be ignored, i.e. not counted but also not treated as breaks in the runs of negative numbers. Easy fix to change that, just change <= 0 to < 0, i.e. this version adjusted to reference column H and with added IF function

    =IF(MAX(FREQUENCY(IF($H$2:$H$10<0,ROW($H$2:$H$10)),IF($H$2:$H$10>0,ROW($H$2:$H$10))))>=5,"Yes")

    confirm with CTRL+SHIFT+ENTER
    Audere est facere

  19. #19
    Forum Expert
    Join Date
    10-02-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    1,222

    Re: counting consecutive days of loss while ignoring zero values

    Ah @daddylonglegs seems to have it. I was under the impression we wanted to count 0's, but reading it seems only considering 0's as not breaking the consecutive string of negatives while only counting negatives. Good catch.

  20. #20
    Registered User
    Join Date
    01-16-2018
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    11

    Re: counting consecutive days of loss while ignoring zero values

    Daddylonglegs....Thank you so much!! that one did the trick!! And, thank you to everyone who responded to this thread.

+ 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. Average Ignoring Zero Values - Non-consecutive cells
    By a7mad3wies in forum Excel General
    Replies: 2
    Last Post: 12-05-2013, 02:13 AM
  2. Replies: 5
    Last Post: 12-04-2013, 04:54 AM
  3. [SOLVED] Excel 2010 Average Ignoring Zero Values - Non-consecutive cells
    By lanos in forum Excel Formulas & Functions
    Replies: 15
    Last Post: 10-23-2013, 07:28 PM
  4. [SOLVED] Consecutive win/loss and current win/loss streak
    By TK2013 in forum Excel Formulas & Functions
    Replies: 16
    Last Post: 09-18-2013, 09:15 AM
  5. Counting Maximum Consecutive Days
    By Delleeb in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 08-26-2013, 03:51 PM
  6. 1. consecutive days of profit and of losses 2. biggest profit loss since date
    By xbohemianx in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 05-14-2013, 12:57 PM
  7. Replies: 2
    Last Post: 10-14-2012, 09:19 AM
  8. Replies: 3
    Last Post: 06-17-2010, 03:04 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