+ Reply to Thread
Results 1 to 17 of 17

Countif Date falls within Range that's <24 hrs

  1. #1
    Registered User
    Join Date
    12-18-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    44

    Countif Date falls within Range that's <24 hrs

    I've looked and I think I'm close but no cigar.


    I'm trying to figure out how to Countif a range that represents each month. There is no constant for each month. I mean that there isn't a set amount of data for each. January could have 22 cells, Feb could have 20. It changes from month to month. Currently, I have to manually update the formula in column D to match the range that corresponds to each date.

    What I would like is a formula that would would find the end of data for January and count if it's <24hrs.

    Book32.xlsx

  2. #2
    Forum Expert Ace_XL's Avatar
    Join Date
    06-04-2012
    Location
    UAE
    MS-Off Ver
    2016
    Posts
    6,074

    Re: Countif Date falls within Range that's <24 hrs

    Try

    =SUMPRODUCT((TEXT($A$2:$A$48,"mmmm")="January")*($B$2:$B$48<24))
    or
    =SUMPRODUCT((MONTH($A$2:$A$48)=1)*($B$2:$B$48<24))
    Life's a spreadsheet, Excel!
    Say thanks, Click *

  3. #3
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Countif Date falls within Range that's <24 hrs

    Try this in D2 and filled down to D12
    =COUNTIFS(A:A,">="&C2&1,A:A,"<"&C3&1,B:B,"<24")

    D13 will have to get adjusted to
    =COUNTIFS(A:A,">="&C13&1,A:A,"<"&C13&31,B:B,"<24")

  4. #4
    Registered User
    Join Date
    12-18-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    44

    Re: Countif Date falls within Range that's <24 hrs

    Ace_XL; It worked but partially. I think it was counting the blanks when I changed the range to 5000.

    Quote Originally Posted by Jonmo1 View Post
    Try this in D2 and filled down to D12
    =COUNTIFS(A:A,">="&C2&1,A:A,"<"&C3&1,B:B,"<24")

    D13 will have to get adjusted to
    =COUNTIFS(A:A,">="&C13&1,A:A,"<"&C13&31,B:B,"<24")
    That works Jonmo1!

    Thank you.

  5. #5
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Countif Date falls within Range that's <24 hrs

    Quote Originally Posted by Jonmo1 View Post
    D13 will have to get adjusted to
    =COUNTIFS(A:A,">="&C13&1,A:A,"<"&C13&31,B:B,"<24")
    Correction
    D13 would have to be
    =COUNTIFS(A:A,">="&C13&1,A:A,"<"&(C13&31)+1,B:B,"<24")

  6. #6
    Registered User
    Join Date
    12-18-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    44

    Re: Countif Date falls within Range that's <24 hrs

    How do you change that code to look at >24 and <48?

    Once I have that, it will be done. Freaking awesome!

  7. #7
    Forum Expert Ace_XL's Avatar
    Join Date
    06-04-2012
    Location
    UAE
    MS-Off Ver
    2016
    Posts
    6,074

    Re: Countif Date falls within Range that's <24 hrs

    =SUMPRODUCT((MONTH($A$2:$A$48)=1)*($B$2:$B$48>24)*($B$2:$B$48<48))

    blanks will get taken care of due to the extra conditions

    EDIT: rephrased
    Last edited by Ace_XL; 07-01-2013 at 04:34 PM.

  8. #8
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Countif Date falls within Range that's <24 hrs

    Quote Originally Posted by Ace_XL View Post
    =SUMPRODUCT((MONTH($A$2:$A$48)*1=1)*($B$2:$B$48>24)*($B$2:$B$48<48))

    blanks will get taken care of
    I don't think that will make it ignore blanks in A
    MONTH(blankcell) = 1
    1*1 = 1 = True

    The new formula ignores blanks because of the dual criteria on B (> 24 AND < 48)
    But the original with just the 1 criteria <24, it would still count blanks in column A.

  9. #9
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Countif Date falls within Range that's <24 hrs

    For my syntax, to do > 24 and < 48

    Try this in D2 and filled down to D12
    =COUNTIFS(A:A,">="&C2&1,A:A,"<"&C3&1,B:B,">24",B:B,"<48")

    D13 will have to get adjusted to
    =COUNTIFS(A:A,">="&C13&1,A:A,"<"&(C13&31)+1,B:B,">24",B:B,"<48")
    Last edited by Jonmo1; 07-01-2013 at 04:51 PM.

  10. #10
    Registered User
    Join Date
    12-18-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    44

    Re: Countif Date falls within Range that's <24 hrs

    Forgive my ignorance Jonmo1. What do I change to count values >24 and <48?

    Currently I have
    Please Login or Register  to view this content.

  11. #11
    Banned User!
    Join Date
    10-14-2006
    Posts
    1,211

    Re: Countif Date falls within Range that's <24 hrs

    Quote Originally Posted by Jonmo1 View Post
    Correction
    D13 would have to be
    =COUNTIFS(A:A,">="&C13&1,A:A,"<"&(C13&31)+1,B:B,"<24")
    Your formula will fail if months are not in ordered

    Try it this way:

    =COUNTIFS(A:A,">="&C2&1,A:A,"<"&EDATE(C2&1,1),B:B,"<24")

  12. #12
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Countif Date falls within Range that's <24 hrs

    Quote Originally Posted by vzwtester View Post
    Forgive my ignorance Jonmo1. What do I change to count values >24 and <48?

    Currently I have
    Please Login or Register  to view this content.
    I had left out an adjustment to the first formula in my last post.
    I've corrected it now, refresh your browser and see post #9

  13. #13
    Registered User
    Join Date
    12-18-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    44

    Re: Countif Date falls within Range that's <24 hrs

    You guys are wonderful. Thank you for helping with this.

    I'm come across one more issue, then I'm done I promise. How do you count the data in the same range for each month that shows NC or 0?

  14. #14
    Registered User
    Join Date
    12-18-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    44

    Re: Countif Date falls within Range that's <24 hrs

    My code is like this at the moment but it's hard coded.

    Please Login or Register  to view this content.

  15. #15
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Countif Date falls within Range that's <24 hrs

    Glad to help so far,

    for the new criteria I think you need to post another book with examples and expected results.

  16. #16
    Registered User
    Join Date
    12-18-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    44

    Re: Countif Date falls within Range that's <24 hrs

    I figured it out by using what you already provided. I just needed to count when the data said NC instead of NC and 0.

    Please Login or Register  to view this content.

  17. #17
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Countif Date falls within Range that's <24 hrs

    Great, glad it worked out.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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