+ Reply to Thread
Results 1 to 24 of 24

Help with a conditional count to avoid counting repeated subsequent occurences...?

  1. #1
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Help with a conditional count to avoid counting repeated subsequent occurences...?

    Hi all,

    I have a table where I want to perform a count.

    It basically measures a value at time intervals 10:00, 11:00, 12:00, ..., 16:00. The first requirement is a Yes at 16:00. If it's a Yes at 16:00, I want to count where the Yes first happened.

    If the condition is fulfilled at say 10:00, it will be fulfilled at the later intervals also. I'm basically interested in knowing and counting in which interval it happened and don't do a double count.

    On the first row, you'll see that a Yes was first recorded at 12:00 and then at subsequent time slots also. I've marked yellow to show where it first happened. For that row, I want to make a count only at 12:00 and ignore the rest of the day/row.

    The right is a matrix where I just did a manual count now to show what I mean. I want to count where it first happens.

    Uten navn.png

    Is there some kind of general formula which can be implemented to perform this count?

    I would prefer to not set up a matrix as show to the right. It was just an example I made to show how I want to count.

    Ideally, I'll just have slots lined up as in the header and then have a frequency count at each associated cell below like this:

    Uten navn1.png

    Thanks very much in advance!
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: Help with a conditional count to avoid counting repeated subsequent occurences...?

    If needed, I can set up my tables differently. But my basic raw data is columns with Yes/No at various time slots so that's what I have to work with.

  3. #3
    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,061

    Re: Help with a conditional count to avoid counting repeated subsequent occurences...?

    In N14, copied across and down:

    =IF(SUM($M14:M14)>0,"",IF(Tabell1[@[10:00]]="Yes",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

  4. #4
    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: Help with a conditional count to avoid counting repeated subsequent occurences...?

    I interpreted a little differently. This does not require the matrix in N14:T24.

    In N26 and filled to the right.
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Dave

  5. #5
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: Help with a conditional count to avoid counting repeated subsequent occurences...?

    Thanks a lot guys! Both work, but I was indeed wishing to not have a matrix, but merely a count in one single row.

    I haven't checked it in detail as I'm at work, but looks like Dave nailed it here.

    Quote Originally Posted by FlameRetired View Post
    I interpreted a little differently. This does not require the matrix in N14:T24.

    In N26 and filled to the right.
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    This formula is currently a bit above my head, so I don't fully understand it.

    But can OFFSET be implemented with this one?

    I typically use OFFSET on all my statistical formulas in order to have a dynamic lookback period where OFFSET references a cell value (5, 10, 15, etc.)

    Thanks in advance.

    Elijah

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

    Re: Help with a conditional count to avoid counting repeated subsequent occurences...?

    Does this right?

    F26 drag across

    =SUMPRODUCT((Tabell1[10:00]="Yes")-(E14:E24="yes"))

    or

    =SUMPRODUCT(--(MMULT(--($F14:F24="Yes"),ROW(INDIRECT("1:"&COLUMNS($F14:F24)))^0)=1))
    Attached Files Attached Files

  7. #7
    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,061

    Re: Help with a conditional count to avoid counting repeated subsequent occurences...?

    Nice one. Bo_Ry's MMULT is (IMHO) the most robust, as it still gives the correct count should any of the the subsequent YES values be NO.

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

    Re: Help with a conditional count to avoid counting repeated subsequent occurences...?

    Glenn, It's very kind of you
    And good point on subsequent YES, NO, I didn't notice that.

  9. #9
    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: Help with a conditional count to avoid counting repeated subsequent occurences...?

    Quote Originally Posted by Glenn Kennedy View Post
    ... it still gives the correct count should any of the the subsequent YES values be NO.
    I had wondered about that as well. Then noticed this from Post #1.
    If the condition is fulfilled at say 10:00, it will be fulfilled at the later intervals also.
    . Hopefully that is true.

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

    Re: Help with a conditional count to avoid counting repeated subsequent occurences...?

    I saw that... but the MMULT approach is just more robust, in that it allows for the statement to be untrue.

  11. #11
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: Help with a conditional count to avoid counting repeated subsequent occurences...?

    Thanks a lot everyone. Great work!

    Could OFFSET be utilized for these formulas in order to have a dynamic lookback period?

    Cell G4 shows how I've implemented a count for "Yes" at 10:00 using an OFFSET value in the cell above.

    Could the same be done for this formula?

    Thanks in advance.

    EDIT: I did try it on the MMULT, but it did not work out correctly...
    Attached Files Attached Files

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

    Re: Help with a conditional count to avoid counting repeated subsequent occurences...?

    I guess 15 mean 15:00

    Please try

    =SUM(MMULT(--(OFFSET(E14:F24,,MATCH(G3,INDEX(HOUR(Tabell1[ #Headers]),),)-1)="Yes"),{-1;1}))
    or
    =SUMPRODUCT(--(MMULT(--(OFFSET($F14:F24,,,,MATCH(G3,INDEX(HOUR(F13:L13),),))="Yes"),ROW(INDIRECT("1:"&MATCH(G3,INDEX(HOUR(F13:L13),),)))^0)=1))
    Attached Files Attached Files

  13. #13
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: Help with a conditional count to avoid counting repeated subsequent occurences...?

    Quote Originally Posted by Bo_Ry View Post
    I guess 15 mean 15:00
    Thank you, Bo_Ry!

    15 is not 15:00, but should refer to number of rows. The OFFSET starts at Row 14. So OFFSET value 15 means count from Row 14 and 15 rows down. : )
    A typical dataset for me is 1500 rows. Often I would want to check maybe the top 15 rows. Then I would use OFFSET 15. Or 10.
    Does that change your implementation of the formula?

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

    Re: Help with a conditional count to avoid counting repeated subsequent occurences...?

    I see, please try

    =SUM(MMULT(--(OFFSET(E14:F14,,MATCH(RIGHT(F4,5),F13:L13,)-1,$G$3-13)="Yes"),{-1;1}))
    or
    =SUMPRODUCT(--(MMULT(--(OFFSET(F14,,,$G$3-13,MATCH(RIGHT(F4,5),F13:L13,))="Yes"),ROW(INDIRECT("1:"&MATCH(RIGHT(F4,5),F13:L13,)))^0)=1))
    Attached Files Attached Files

  15. #15
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: Help with a conditional count to avoid counting repeated subsequent occurences...?

    Hi, Bo,

    I'm at work, so could only test it very briefly, but changing values in the input cell G3 does not seem to make changes to calculated values?

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

    Re: Help with a conditional count to avoid counting repeated subsequent occurences...?

    Please try to change G3 to 24 and F4 to "# Yes @ 10:00" and see

  17. #17
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: Help with a conditional count to avoid counting repeated subsequent occurences...?

    Quote Originally Posted by Bo_Ry View Post
    Please try to change G3 to 24 and F4 to "# Yes @ 10:00" and see
    Hi,

    Thank you!

    Why G3 = 24?

    Also, I didn't intend on using "# Yes @ 10:00" as input. That was just a text line showing the calculation I first made to count the # Yes @ 10:00 using OFFSET.

    My wish is to have the OFFSET function implemented for the entire row you first created in post #6.

    Maybe I have what I need to figure this out on my own. I can check when I'm back from work.

    Best regards and thanks again!

    Elijah

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

    Re: Help with a conditional count to avoid counting repeated subsequent occurences...?

    ่๊Just for testing, You and key any value from 14-24, G3 is offset for row

    And the @ 10:00 is for show data at that time, F4 is offset for column

  19. #19
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: Help with a conditional count to avoid counting repeated subsequent occurences...?

    Hi, Bo_Ry,

    Many thanks again.

    I tried to implement your OFFSET, but couldn't quite figure it out. I have now taken your elegant formula and implemented it for my entire table.

    Glenn Kennedy was also right in that it is very good for avoiding a count when there is no "Yes" at 16:00. I know I wrote that. The plan was to somehow filter out the No values at 16:00. But this way is much better.

    I've applied your MMULT formula to cells B9:H9. It currently works great for the entire table.

    Uten navn.png

    In Cell J9 I'm doing a count of column I based on an OFFSET formula and the cell value in B3.

    It is the same general formula I would like to implement for the formula in cell B9:H9.

    I've decided that this is not very important for me, but if it's possible, why not.

    Anyway, thank you for all help! Really appreciated.

    Best regards,

    Elijah
    Attached Files Attached Files

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

    Re: Help with a conditional count to avoid counting repeated subsequent occurences...?

    Glad that you can apply.

    If you still need offset, Please try at

    B14:I14
    =SUMPRODUCT(--(MMULT(--(OFFSET($B21:B21,,,$B$3)="Yes"),ROW(INDIRECT("1:"&COLUMNS($B21:B21)))^0)=1))
    Attached Files Attached Files

  21. #21
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: Help with a conditional count to avoid counting repeated subsequent occurences...?

    Quote Originally Posted by Bo_Ry View Post
    Glad that you can apply.

    If you still need offset, Please try at

    B14:I14
    =SUMPRODUCT(--(MMULT(--(OFFSET($B21:B21,,,$B$3)="Yes"),ROW(INDIRECT("1:"&COLUMNS($B21:B21)))^0)=1))
    Amazing!

    Works great.

    I wish I could give you more reputation, but not allowed (yet).

    Thanks again for all help!

    Elijah

  22. #22
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: Help with a conditional count to avoid counting repeated subsequent occurences...?

    I added another related column labeled Open in B21. This is simply numerical data, positive and negative.

    I would be interesting to me to see if there's any differences between a positive and a negative open when counting # Yes.

    Uten navn.png

    I tried to implement this by using IFS, but I get an error:

    Please Login or Register  to view this content.
    Is it possible somehow?

    The best would be to use the drop down menu in Cell B5 with possible values: positive, negative and all.

    Positive = >0
    Negative = <0
    All = all days in the data set

    I was able to implement the formula for All days as that one obviously is easy.

    Please Login or Register  to view this content.

    Not sure if the conditional count is possible when the formula is this complex? I imagined I could do it with IF, but didn't quite nail it down.

    I have other ways to find out this result. I can filter data and copy and paste it. But easier for the future with a formula if possible.

    Best regards and thanks.

    Elijah
    Attached Files Attached Files

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

    Re: Help with a conditional count to avoid counting repeated subsequent occurences...?

    Please try at C9,

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

  24. #24
    Forum Contributor
    Join Date
    03-31-2010
    Location
    Norway
    MS-Off Ver
    Excel 365
    Posts
    632

    Re: Help with a conditional count to avoid counting repeated subsequent occurences...?

    Amazing, Bo_Ry!

    That worked out great. I'm very impressed. When I get time on Sunday, I will sit down with that formula and try to actually understand it.

    Thank you for all your help and have a great day!

    Best regards,

    Elijah

+ 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] Trouble with COUNTIF formula on conditional count - I want to avoid counting text.
    By Elijah in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 01-07-2019, 08:16 AM
  2. [SOLVED] Counting occurences
    By RickMcc in forum Excel General
    Replies: 20
    Last Post: 03-21-2018, 08:18 AM
  3. [SOLVED] Number of occurences for the most repeated value
    By YasserKhalil in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 11-13-2015, 12:53 AM
  4. Replies: 2
    Last Post: 05-14-2015, 11:17 AM
  5. Replies: 9
    Last Post: 10-17-2011, 04:33 PM
  6. Repeated action. Is it possible to avoid loop ?
    By Jasutasu in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-18-2011, 01:44 PM
  7. Counting the occurences
    By riomarde in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-27-2006, 04:10 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