+ Reply to Thread
Results 1 to 14 of 14

Count consecutive values above or below 50 depending on the last value in the column

  1. #1
    Registered User
    Join Date
    07-08-2015
    Location
    New York, NY
    MS-Off Ver
    2010
    Posts
    6

    Count consecutive values above or below 50 depending on the last value in the column

    Hello,

    I have for example the following set of data:

    51
    52
    53
    49
    52
    51
    48
    47

    I am hoping someone knows a formula that can count the consecutive values above or below 50 depending on the last value in the column.
    In this case becuase the last value (ie 47) is below 50, the formula should return 2 (counts 47 and 48).

    If the data set was:

    51
    52
    53
    49
    52
    51
    52
    53

    The formula should return 4 (counts 53, 52, 51 and 52).

    I have been scouring the internet for a solution with no avail. Hoping someone has a solution for this.
    Appreciate your help.

  2. #2
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: Count consecutive values above or below 50 depending on the last value in the column

    what should it return for 51,52,53,54 ? Would that be 4 also, or 3?
    Last edited by GeneralDisarray; 07-08-2015 at 11:14 AM.
    Remember, saying thanks only takes a second or two. Click the star icon(*) below the post you liked, to give some Rep if you think an answer deserves it.

    Please,mark your thread [SOLVED] if you received your answer.

  3. #3
    Registered User
    Join Date
    07-08-2015
    Location
    New York, NY
    MS-Off Ver
    2010
    Posts
    6

    Re: Count consecutive values above or below 50 depending on the last value in the column

    The dividing line is 50. So for the values you indicated it should return 4

  4. #4
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Count consecutive values above or below 50 depending on the last value in the column

    Nevermind, I misread the problem :/
    Last edited by ChemistB; 07-08-2015 at 11:23 AM.
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  5. #5
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: Count consecutive values above or below 50 depending on the last value in the column

    Hmm. I'm not sure I see the logic -- in your example 51,52,53,49,52,51,52,53 it would seem to show 6 values consecutive - or 7 if I count the ...,52,51,... for positions 5 and 6

    What am I missing?

  6. #6
    Registered User
    Join Date
    07-08-2015
    Location
    New York, NY
    MS-Off Ver
    2010
    Posts
    6

    Re: Count consecutive values above or below 50 depending on the last value in the column

    General,

    I think i see what you are doing - let me rephrase what i am looking to achieve.

    I have a series of data that comes in monthly.
    If the last value is below 50, I want a function that will count how many consecutive months the reading was below 50.
    At the same time the function needs to count how many consecutive months the reading was above 50, if the last value was above 50.

    So if I have the following data on month 5

    month 1: 51
    month 2: 49
    month 3: 51
    month 4: 52
    month 5: 53

    With the fifth month being the most recent and therefore the starting point.

    The function should return a 3.

    Now in month 6:

    month 1: 51
    month 2: 49
    month 3: 51
    month 4: 52
    month 5: 53
    month 6: 49

    The function needs to return a 1.

    Does that help?

  7. #7
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,613

    Re: Count consecutive values above or below 50 depending on the last value in the column

    Tried few minutes with standard formulas - were also taking into account data from months ago :-P so gave up at the moment, and I'd go for simple UDF (user defined function);

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


    Can be written better, but have to go off-line, and ... seems to work - see sample file.
    Attached Files Attached Files
    Best Regards,

    Kaper

  8. #8
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: Count consecutive values above or below 50 depending on the last value in the column

    OHHHHH! right.. that's different

    Don't know a single formula to get you there - I'm sure you could do it, but it would be pretty clever. Why not just add some helper columns (see attached)?


    Edit - saw reply from Kaper. Yes, you could also go VBA with it
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    07-08-2015
    Location
    New York, NY
    MS-Off Ver
    2010
    Posts
    6

    Re: Count consecutive values above or below 50 depending on the last value in the column

    Kaper, unfortunately my firewall is blocking me from opening your attachment.
    I will have to check later on a different computer if that solution works.

    Appreciate you taking the time and will let you know.

  10. #10
    Registered User
    Join Date
    07-08-2015
    Location
    New York, NY
    MS-Off Ver
    2010
    Posts
    6

    Re: Count consecutive values above or below 50 depending on the last value in the column

    Thanks for your help General - I'm going to try and go with Kaper's approach.
    I may need some help implementing the VBA language.

  11. #11
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Count consecutive values above or below 50 depending on the last value in the column

    Okay,
    First I set up two Defined names just to make the formulas clearer

    DataRange = $A$1:INDEX($A:$A, MATCH(9^99, $A:$A))
    LstValue = INDEX($A:$A, MATCH(9^99, $A:$A))
    I am assuming your data begins in cell A1

    Then enter this Array formula

    =IF(LstValue<50, MATCH(9^99,DataRange)-MATCH(2, 1/(DataRange>=50)), MATCH(9^99, DataRange)-MATCH(2, 1/(DataRange<50)))

    ...confirmed by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER. You will know the array is active when you see curly braces { } appear around your formula. If you do not CTRL+SHIFT+ENTER you will get an error or a clearly incorrect answer. Press F2 on that cell and try again.

    See attachment
    Attached Files Attached Files

  12. #12
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: Count consecutive values above or below 50 depending on the last value in the column

    Chemist B... truly is my hero

    \( ⊙ .⊙ )/

    ʕ•͡ᴥ•ʔ

  13. #13
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Count consecutive values above or below 50 depending on the last value in the column

    LOL, thanks General

  14. #14
    Registered User
    Join Date
    07-08-2015
    Location
    New York, NY
    MS-Off Ver
    2010
    Posts
    6

    Re: Count consecutive values above or below 50 depending on the last value in the column

    ChemistB thank you so much - much appreciated!

+ 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. Formula to Count Consecutive Blank Cells in a Range Depending on Today's Date
    By tophatpete in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 11-28-2020, 05:12 AM
  2. How would you count (& denote) consecutive values in a column?
    By schill2 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 11-24-2013, 12:16 PM
  3. Replies: 5
    Last Post: 04-21-2011, 05:22 PM
  4. Count values in one column depending on value in a second
    By genus in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-28-2008, 09:07 AM
  5. [SOLVED] Count Intervals of 2 Consecutive Values in same Row and Return Count across Row
    By Sam via OfficeKB.com in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 11-29-2005, 11: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