+ Reply to Thread
Results 1 to 15 of 15

Count occurrences of value in a date range I can specify easily each time

  1. #1
    Registered User
    Join Date
    07-07-2014
    Location
    LA
    MS-Off Ver
    14.4.1
    Posts
    7

    Count occurrences of value in a date range I can specify easily each time

    Hi folks, I've been searching and have found similar threads for answers but can't seem to get anything working myself. I'm hoping someone can help.

    Column A is date mm/dd/yyyy
    Column B is general format and is based off a calculated formula. Values look like "12/3" and "19/1", etc.

    I'd like to find the number of occurrences of a value specified in a given date range. For example, how many 12/3's are there from 1/1/1900 - 12/31/1901.

    I can do this with this formula where B4 is 12/3, and the range of of rows B4-B369 in this case is one year, =COUNTIF($B$4:$B$369,B4)

    However I need the date to be dynamic as well as to be able to enter in whatever I want for the value. Ideally, I'll have A1 reserved to enter in a start date, A2 an end date, and B1 an entry for the value.

    Thanks in advance -
    Mika

  2. #2
    Valued Forum Contributor
    Join Date
    07-07-2014
    Location
    Washington DC
    MS-Off Ver
    2007
    Posts
    1,047

    Re: Count occurrences of value in a date range I can specify easily each time

    =COUNTIFS will allow you to include multiple criteria. Just create cells for your start and end dates, then add criteria that the cells be between your start dates (e.g., $B$4:$B$369>start_date_cell,$B$4:$B$369<end_date_cell)

  3. #3
    Forum Expert Vikas_Gautam's Avatar
    Join Date
    06-04-2013
    Location
    Ludhiana,Punjab, India
    MS-Off Ver
    Excel 2013
    Posts
    1,850

    Re: Count occurrences of value in a date range I can specify easily each time

    =count(if(($A:$A<=c1)*($B:$B<=d1),Row($A:$A)))

    put date in the a1 ..
    And required no. In d1
    use ctrl shift enter to enter the formula..

    Say thanks, click *

  4. #4
    Registered User
    Join Date
    07-07-2014
    Location
    LA
    MS-Off Ver
    14.4.1
    Posts
    7

    Re: Count occurrences of value in a date range I can specify easily each time

    So I have
    A1 start date
    A2 end date
    B1 entry where I type in 12/3
    B2 where I put the following formula which is supposed to display the count
    =COUNTIF($B$4:$B$369,B1)>$A$1,$B$4:$B$369<$A$2)

    However I'm getting an error. (I apologize for my noobieness..)

  5. #5
    Forum Expert Vikas_Gautam's Avatar
    Join Date
    06-04-2013
    Location
    Ludhiana,Punjab, India
    MS-Off Ver
    Excel 2013
    Posts
    1,850

    Re: Count occurrences of value in a date range I can specify easily each time

    =count(if(($A:$A>=a1)*($A:$A<=a2)*($B:$B<=B1),Row($A:$A)))

    hey man replace the $A:$A with your date range... And $B:$B with your no. Range..

    Use ctrl shift enter to enter the formula...

  6. #6
    Registered User
    Join Date
    07-07-2014
    Location
    LA
    MS-Off Ver
    14.4.1
    Posts
    7

    Re: Count occurrences of value in a date range I can specify easily each time

    Hi Vikas - it's close but not quite. I'm keeping my range to one year for now to make sure results are accurate. My date range is in A3-A368. So here is the full formula:

    =COUNT(IF(($A$3:$A$368<=A1)*($A$3:$A$368<=A2)*($B$3:$B$368<=B1),ROW($A3:$A368)))

    And of course I'm using ctrl+sft+enter and seeing the {} surrounding. It's giveng me a result of 1 when it should be 4.

  7. #7
    Forum Expert Vikas_Gautam's Avatar
    Join Date
    06-04-2013
    Location
    Ludhiana,Punjab, India
    MS-Off Ver
    Excel 2013
    Posts
    1,850

    Re: Count occurrences of value in a date range I can specify easily each time

    Okay do you want to include both dates if no then remove the = signs in both conditions....

  8. #8
    Forum Expert Vikas_Gautam's Avatar
    Join Date
    06-04-2013
    Location
    Ludhiana,Punjab, India
    MS-Off Ver
    Excel 2013
    Posts
    1,850

    Re: Count occurrences of value in a date range I can specify easily each time

    Oh i found the problem..
    Your first date condition is wrong which should be >=

  9. #9
    Registered User
    Join Date
    07-07-2014
    Location
    LA
    MS-Off Ver
    14.4.1
    Posts
    7

    Re: Count occurrences of value in a date range I can specify easily each time

    I want both dates. A1 will be entered a start date and A2 an end date. So there'll always be two dates.

    The date range is listed in A3-A368. Next to each date is a value in B3-368.

  10. #10
    Registered User
    Join Date
    07-07-2014
    Location
    LA
    MS-Off Ver
    14.4.1
    Posts
    7

    Re: Count occurrences of value in a date range I can specify easily each time

    Cool, well that fixed it for the first value I put in which is 12/3, but when I test it for another one which is 13/4, it appears to be adding in 12/3's occurrences too. Should ($B$3:$B$368<=B1) not have the < in it?

  11. #11
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Count occurrences of value in a date range I can specify easily each time

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  12. #12
    Registered User
    Join Date
    07-07-2014
    Location
    LA
    MS-Off Ver
    14.4.1
    Posts
    7

    Re: Count occurrences of value in a date range I can specify easily each time

    Yep, that fixed that adding problem. I changed the lookup value part to just = and it appears to be working in your formula. Thank you so much for the help! Much appreciated!

    =COUNT(IF(($A$3:$A$368>=A1)*($A$3:$A$368<=A2)*($B$3:$B$368=B1),ROW($A3:$A368)))

  13. #13
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Count occurrences of value in a date range I can specify easily each time

    Try this...

    =COUNTIFS(A4:A100,">="&A1,A4:A100,"<="&A2,B4:B100,B1)

    Adjust the ranges to suit.

    I'm assuming column B is formatted as TEXT.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  14. #14
    Registered User
    Join Date
    07-07-2014
    Location
    LA
    MS-Off Ver
    14.4.1
    Posts
    7

    Re: Count occurrences of value in a date range I can specify easily each time

    So far this is working nicely. How would I put the percentage of days in a different cell? For example if the below example for a count on the value 12/3 on two days, 1/1/2000 through 1/2/2000 shows one day with that value (count of 1), I'd like in a nearby cell (we'll call B2) the percentage of days, in this case 50% since it was one of two days.

    =COUNT(IF(($A$3:$A$368>=A1)*($A$3:$A$368<=A2)*($B$3:$B$368=B1),ROW($A3:$A368)))

  15. #15
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Count occurrences of value in a date range I can specify easily each time

    mikalaka please update tor profile to say which version of excel you have i'm assuming it is 2010

+ 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] Count the occurrences of 3 words in a range
    By tlacloche in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 05-20-2014, 10:54 AM
  2. [SOLVED] Count Occurrences Date Range Falls Within Month
    By Rbooth in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 02-25-2014, 06:47 PM
  3. [SOLVED] Count occurrences of text in a range
    By braydon16 in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 03-18-2013, 08:33 PM
  4. [SOLVED] Count Occurrences and Fill Cells with Results Using a Date Range
    By CWatsonJr in forum Excel General
    Replies: 20
    Last Post: 06-07-2012, 02:33 PM
  5. Count time occurrences across multiple sheets
    By Lea724 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-14-2011, 09:03 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