+ Reply to Thread
Results 1 to 29 of 29

Counting number of records in a given date range.

  1. #1
    Registered User
    Join Date
    01-15-2013
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    53

    Counting number of records in a given date range.

    I've searched around and read various stuff on countif's, and dcount but I don't think they quite solve my problem.

    I have two worksheets, one is a daily recording of patients behaviour with incidents of various types of behaivour being recorded as a number in different columns. Seperate incidents on the same day are entered on a seperate row, so 14/01/2013 may have 3 rows for 3 behaviours and 15/01/2013 may have none or 5 or whatever.

    The second worksheet is a tally of the weekly occurance of each behaviour, thus it records the incidences where a number greater than 0 is present in the relevant column and tallies that with all incidences for that week (this is currently done manually and is the formula I am after).

    A countif can easily be used to count the number of records between a given set of cells (thus dates) but this only works for the past as for future weeks there is no way of knowing what the cell range for a given week will be as each new incident creates a new line.

    What i'm looking for is a formula that does:
    Counts the number of cells with a value greater than 0 in a given column that is between the date 01/01/2013 and 08/01/2013 and automatically adjusts the cell range to encompass those dates (so it uses the date from column A and adds the records from column B,C,D or whichever). The data is taken from the first worksheet and displayed on the second. The date range is also present on the second worksheet in column A thus: 01/01/2013-08/01/2013 to give the week it covers.

    The formula needs to be able to be dragged down to the cells so that when I enter the data into the raw data file it automatically adjusts the cell range on the weekly worksheet and adds it up.

    I hope that makes sense as is possible! Thanks.

    Using excel 2003.

  2. #2
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Counting number of records in a given date range.

    Looks like Dynamic Named Ranges and SUMPRODUCT() will be the way to go with 2003.

    Can you post a dummy workbook?
    Remember to disguise any potentially sensitive data.
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  3. #3
    Registered User
    Join Date
    01-15-2013
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    53

    Re: Counting number of records in a given date range.

    I'm not sure if I'm allowed to upload or download information from work due to virus potential, etc. If a dummy workbook is essential then I will make one this evening and upload from home.

    I'll have a look at Dynamic named ranged and sumproduct when I get a chance and see if I can make heads or tails of it.

    Thanks.

  4. #4
    Registered User
    Join Date
    01-15-2013
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    53

    Re: Counting number of records in a given date range.

    I've had a look at dynamic named ranges and I'm not entirely sure what they are supposed to do - something along the lines of expanding the range of cells dynamically?

    Will it be essential to upload a dummy file?

  5. #5
    Forum Expert Kevin UK's Avatar
    Join Date
    12-07-2010
    Location
    Radstock, Somerset
    MS-Off Ver
    365
    Posts
    1,922

    Re: Counting number of records in a given date range.

    Hi Sinnie

    Yes, Marcol probably just needs to see how your data is set out.
    Regards Kevin


    Merged Cells (They are the work of the devil!!!)

  6. #6
    Registered User
    Join Date
    01-15-2013
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    53

    Re: Counting number of records in a given date range.

    Ok, an example is attached. All information is completely fictional.
    I think it should be sufficient for our purposes.

    The raw data has consecutive dates in column A. The first behaviour of the day is input in the same row as the date, subsequent behaviours are placed on rows belong thus leaving the date cell blank. You then have a time (unimportant) and three categories of behaviour, a 1 is used to indicate that that particular behaviour was present within the specified incident (attempting to climb the fence then kicking someone is two types of behaviour and is all one incident so a '1' is placed in both cells), whether a restraint or PRN meds are used is also indicated by a 1.

    The weekly frq sheet records the combined frequencies of each occurance for the week. The problem, as outlined in the first post is that a singular formula can not be used to count the number of incidents because the number of rows for each day is not constant. The issue is to make a formula that can modify its data range according to the date and how many rows that involves.


    Thanks
    Attached Files Attached Files

  7. #7
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Counting number of records in a given date range.

    Okay, the first problem is that Column A doesn't have a continuous list of dates.

    I have added Column J, it can be retained as a helper column, or to Copy > Paste Special > Values to Column A.

    The second problem is that your sample row of results appears to be wrong.

    I have put a formula in C2 that can be dragged across to G2, then down.
    This is based on Column J for now.
    B2 sums C2:G2

    I have filtered Column J for the Dates 01/01/2013-07/01/2013 to allow you to check my result.

    Check this over, I have to go for now, I'll look back later to get your response, and possibly take it forward, if required.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    01-15-2013
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    53

    Re: Counting number of records in a given date range.

    I've only been able to take a quick look tonight and will not be able to download at work tommorow so I shall have to play with it more tommorow.

    The principle of what you have done seems to work fine, if I insert a new row under 05/01/2013, fill it in and insert the date into the the J column then it appears in the weekly frequency. Column A isn't continuous as when looking at a glance it is easier to spot seperate days, wherease if each cell had the date it would be hard to distinguish, this of course necesitates the column you added. Is it possible to get that column to auto fill in based on the first cell above it (in column A) to have a date. Thus, when the new row is created for the new record, it looks up the cells in column A until the first with a date and uses that?

    It appears that the file you sent me is missing some of the data? I created some up until the 15/01/2013. The blank rows are meant to be blank however as not all days will have incidents.

    How do columns C-G on the weekly frq determine which dates to use as filters? Is it drawn from the A column on the same worksheet? If I drag that formula down ad infinitum would it update correctly to always include the next weeks dates as filters for the next row? The idea of course being to add the dates for the next year or so and drag the formula down correspondingly and then never have to check the weekly frq sheet again and just input into the raw data sheet.

    But yes, it appears to work fine as it is. Thanks very much!

  9. #9
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Counting number of records in a given date range.

    Try this workbook.

    I have added Dynamic Names to Sheet "Raw Data"

    I have moved the helper column "Infill Dates" to Column A, this can be hidden with the +/- grouping button.
    This allows you to add more "Behaviour catagory" headers to row 1 without changing the Dynamic Names Formulae.

    When you add a date to Column B, or a time to Column C, Column A will automatically update, and the Named ranges will adjust to suit the last entry.

    To extend the table depth, select the last row and drag down as required.
    To extend the table width, just add a new catagory header.

    In Sheet "Weekly Frq" enter your first Date in A2, the remaining dates will update in weekly increments.

    If you add new catagories to "Raw Data", add exactly the same header to this sheet, then drag the formula in G2 across and down.
    The headers in this Sheet from Column C right need not be in the same order as those in Sheet "Raw Data" Column D right.
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    01-15-2013
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    53

    Re: Counting number of records in a given date range.

    I've been able to download at work, which is good.

    Anyway, I've had a good play around with everything and got it all to work, except I realise an omission on my part has caused a slight problem. The raw data worksheet, with the types of behaviour columns will actually be used to record the severity of the behaviour (1-4 for example). If the same behaviour occurs twice in one day then it is entered as a seperate incident on a new line. in the weekly frq's worksheet it currently sums the entries into the behaviour cells in Raw Data. I tried swapping SUMPRODUCT for COUNT but it just returned 0 as a result. If it isn't possible to count the number of entries then I can just include the severity elsewhere.

    The spreadsheet is now operating significantly slower, is this a result of it now calculating across multiple cells and worksheets? I have extended it down to 500 cells as there is a lot of back data to be added. Will this only get worse if I add graphs?

    If this file starts to slow down is it possible to create a second excel file that pulls the information from this one to make the graphs which would then work faster?

    Is there any way to make this system work but on a monthly basis? Currently it works on taking the previous date and adding 7 for the week, but obviously this will not work for months due to different lengths.

    Last question, is it possible to copy the formula automatically from the infill dates to a newly created row. So if I insert a line between two rows that are already filled in then the formula is created instantly in infill dates.

    Other than that it appears to work perfectly, thanks very much!
    Last edited by Sinnie; 01-17-2013 at 10:43 AM.

  11. #11
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Counting number of records in a given date range.

    Let's take this a step at a time!

    See if this Counts the instances of monthly incidents, as you need.

    Sheet "Raw Data" now has an Excel List instead of a table.
    To extend the table, Select any cell within the List, then drag the bottom right corner down, or add data to the last row beginning with Column B, the formula in Column A will be automatically generated.
    Similarly, if you insert a row the formulae in Column A will automatically adjust.

    With Sheet "Monthly Frq" enter your start date in A2 as for example if you want the results to start with February, enter 1/2/2013,
    EOMONTH() calculates the number of days to increment/count.
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    01-15-2013
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    53

    Re: Counting number of records in a given date range.

    Sorry for bombarding you with questions! I'm a little out of my depth and as usual, a simple idea requires a rather more complex solution.

    The excel list works perfectly, thanks.
    As does the auto month fill in, however the cells all list #NAME? and I have found multiple potential reasons for this and can't make heads or tails of it.

    I'm attaching the file I worked on from your earlier upload. It has all the columns that will be required with the requisite ones filled in on the weekly - the monthly one will contain the same. Again, all data included is fictional.

    All i need to do is change it to count the number of entries instead of summing then it should be ready to go.

    One thing I noticed about the slow-ness is that if I type in a cell then use the arrow keys to move to the next cell, pressing the key once does nothing (even if i wait 10 seconds after typing) but on the second key press it instantly moves over b 2 cells, as if the first key press is queued but not triggered. If I click with the mouse it instantly moves.

    Thanks again
    Attached Files Attached Files

  13. #13
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Counting number of records in a given date range.

    Quote Originally Posted by Sinnie View Post
    ...
    The excel list works perfectly, thanks.
    As does the auto month fill in, however the cells all list #NAME? and I have found multiple potential reasons for this and can't make heads or tails of it.
    ....
    All i need to do is change it to count the number of entries instead of summing then it should be ready to go.
    ....
    Using an Excel List will slow the calculation, but if you want to insert rows mid table without manually updating the formulae, then this is the way to go. It might be faster to use VBa to do this but let's not go that way yet.

    To Sum the severity of the weekly incidents use this in C2
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    To Count the weekly incidents use this
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Where are you getting #NAME? errors, I can't see any in this workbook.
    Attached Files Attached Files

  14. #14
    Registered User
    Join Date
    01-15-2013
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    53

    Re: Counting number of records in a given date range.

    The above attached file of yours (copy of behaviour recording templats PS2.xls), as far as I can tell, works perfectly. I can add records to the raw data with them auto updating into the weekly data sheet. Regarding the severity it will probably just be best to create graphs off them manually as creating yet another sheet to do the same thing as weekly and monthly is just un-needed and it will want min/max/avg - so that's fine.

    The #NAME? error is in the monthly worksheet you uploaded in copy of example(3).

  15. #15
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Counting number of records in a given date range.

    Quote Originally Posted by Sinnie View Post
    The #NAME? error is in the monthly worksheet you uploaded in copy of example(3).
    I am not getting any #NAME? errors. Have you changed, or added, something?

  16. #16
    Registered User
    Join Date
    01-15-2013
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    53

    Re: Counting number of records in a given date range.

    Apologies for the late reply. I have deleted the file and re-downloaded it (copy of example(3)) and it comes up with the #NAME? error straight away on the monthly worksheet, the raw data is fine. It's all the cells except the month column (A).

  17. #17
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Counting number of records in a given date range.

    I've just downloaded "Copy of Example(3)" from post #11 into Excel 2003, and I can't see any #NAME? errors ...

    What version are you using?
    Last edited by Marcol; 01-22-2013 at 06:14 AM.

  18. #18
    Registered User
    Join Date
    01-15-2013
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    53

    Re: Counting number of records in a given date range.

    Microsoft Office Excel 2003, same version as I've been using throughout. Re-downloaded from post #11, "Copy of Example(3)" and the monthly worksheet is full of #NAME? errors.

    Ok, I discovered you can 'trace error' and this is what I have:
    Tracing the error in B2 - blue line from A2 to B2 turning into red line and continuing into C2 then goes diagonally as a dashed blue line to the corner of cells A3/4 and B3/4 - there is also a blue line from C1 down to where the red and blue line meet in C2. Hope that clarifies something!

    I can also evaluate the error but im not really sure how it works.
    Last edited by Sinnie; 01-22-2013 at 06:51 AM.

  19. #19
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Counting number of records in a given date range.

    As I can't replicate the error you are getting, thst means nothing to me.

    Post the workbook you are getting the errors in and I'll see if I can find the error.

    Just a thought, are you using an English version of MS Office?
    I presume you are, as you give your location as UK.

  20. #20
    Registered User
    Join Date
    01-15-2013
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    53

    Re: Counting number of records in a given date range.

    Here, I haven't touched it except downloading it from your post and opening it.

    Yeah, English version.
    Attached Files Attached Files

  21. #21
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Counting number of records in a given date range.

    That opens without error for me, it was however a tad slow in opening, and the "errors" were briefly displayed before clearing.
    I can only assume that your copy of Excel is not refreshing properly.

    Are you using the last version of MS office 2003 with service pack 3 (SP3) installed?

    I'm going to ask others to see if they can replicate your error and shed some light on the problem.

  22. #22
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Counting number of records in a given date range.

    No errors for me, Marcol.
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

  23. #23
    Forum Guru benishiryo's Avatar
    Join Date
    03-25-2011
    Location
    Singapore
    MS-Off Ver
    Excel 2013
    Posts
    5,147

    Re: Counting number of records in a given date range.

    #NAME error probably due to EOMONTH formula in Column C:G? i dont think it exist in Excel 2003 unless you install the add-in. an alternative may be:
    DATE(YEAR(A2),MONTH(A2)+1,0)
    replacing
    EOMONTH($A2,0)

    Thanks, if you have clicked on the * and added our rep.

    If you're satisfied with the answer, click Thread Tools above your first post, select "Mark your thread as Solved".

    "Contentment is not the fulfillment of what you want, but the realization of what you already have."


    Tips & Tutorials I Compiled | How to Get Quick & Good Answers

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

    Re: Counting number of records in a given date range.

    EOMONTH is an Analysis ToolPak function in Excel 2003 - if you don't have that add-in you will get #NAME? error - try installing by using

    Tools > add-ins > tick Analysis ToolPak box

    ....or you can workaround with

    =DATE(YEAR(A1),MONTH(A1)+1,0)

    Edit: as benishiryo says........
    Last edited by daddylonglegs; 01-22-2013 at 08:52 AM.
    Audere est facere

  25. #25
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Counting number of records in a given date range.

    Oh dear, I've had the Analysis ToolPak installed for so long, that I forgot that EOMONTH() was part of it ...

  26. #26
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Counting number of records in a given date range.

    Me too! .............

  27. #27
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,601

    Re: Counting number of records in a given date range.

    I don't see any error

  28. #28
    Registered User
    Join Date
    01-15-2013
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    53

    Re: Counting number of records in a given date range.

    Wonderful! That solved it. Thanks very much.

    I believe this solves the whole case now, with much help from Marcol.

    You have my eternal gratitude.

    Edit: And yet I speak too soon, hopefully it's just a minor one. I realised that I also wanted to calculate the total number of 'incidents' per week/month which is sepeate from total behaviours as multiple behaviours can occur within one incident. The best way I saw to do this was to create a new column in the weekly/monthly worksheet called Incident Number and to copy the formula used on the other columns to obtain the total of incident numbers within each week or month. But it always comes back as 0. All the other columns work and I have added several new ones for behaviours and copied the formula over to them without issue.

    I'm not sure if the worksheets you've had have had incident number on them, it simply started at 1 for the first row then the formula is the cell above+1 to give a unique identifier.
    Last edited by Sinnie; 01-23-2013 at 05:55 AM.

  29. #29
    Registered User
    Join Date
    01-15-2013
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    53

    Re: Counting number of records in a given date range.

    Sorry for double post, just wanted to see if anyone had any ideas. I don't see why it doesn't work just the same as all the other columns?

    Edit: i've got it to work by recreating the incident number column but I've noticed one final little problem. Every row has an incident number regardless of whether there is an incident for that day. I don't have time to look at it in depth now but I will need to find a way to get the incident number to only generate if one of the behaviour columns has a number present in it.
    Last edited by Sinnie; 01-25-2013 at 05:07 AM.

+ 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