+ Reply to Thread
Results 1 to 27 of 27

count and average numbers based off date, not worksheet data is in

  1. #1
    Forum Contributor
    Join Date
    04-02-2013
    Location
    West Palm beach, Fl
    MS-Off Ver
    Excel 2010
    Posts
    113

    count and average numbers based off date, not worksheet data is in

    Hello,

    I have a database of sorts that I am trying to get to function the way I need it to. It's going to be a 12 month cycle, but my attachment, for size sake, is only 3 months. In this instance, I am counting AMAs (medical term for leaving before you are supposed to) and averaging lengths of stay for the AMAs. My formulas right now only count the AMAs listed in the month they are searching in, but as you will notice, sometimes the AMAs occur in the next month, but because the client's admission date was in the prior month, it's being counted in the month of the admission, and not the month the AMA actually occurred. I know I can use a data dump, but the size of this document is actually going to be quite large in its full form, so I'm hoping to find a formula instead. Can anyone help?
    Last edited by nicki_rae22; 05-06-2015 at 01:22 PM.

  2. #2
    Forum Contributor
    Join Date
    04-02-2013
    Location
    West Palm beach, Fl
    MS-Off Ver
    Excel 2010
    Posts
    113
    Oops, here it is
    Attached Files Attached Files

  3. #3
    Forum Contributor
    Join Date
    04-02-2013
    Location
    West Palm beach, Fl
    MS-Off Ver
    Excel 2010
    Posts
    113

    Re: count and average numbers based off date, not worksheet data is in

    Good morning, so no go on my issue anyone?

  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: count and average numbers based off date, not worksheet data is in

    Quote Originally Posted by nicki_rae22 View Post
    Good morning, so no go on my issue anyone?
    Working on it....it's going to take me some time, though.

    Edit Quick question: Rather than referencing across multiple sheets in the formula(s) in the AMAs sheet are you willing to have helper ranges in AMAs sheet (off to the right out of sight) that summarize the relevant columns from each month sheet? It might make for simpler formula(s).
    Last edited by FlameRetired; 05-07-2015 at 12:51 PM.

  5. #5
    Forum Contributor
    Join Date
    04-02-2013
    Location
    West Palm beach, Fl
    MS-Off Ver
    Excel 2010
    Posts
    113

    Re: count and average numbers based off date, not worksheet data is in

    No problem at all! Thank you for your response. I have the data dump plan as a backup, but I'm really trying to avoid that route if at all possible because of size concerns mostly. Also, let me know if there is anything else you need from me! Thanks again.

  6. #6
    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: count and average numbers based off date, not worksheet data is in

    Can you explain how the figures in the row labeled 'Avg. LOS' are determined?

  7. #7
    Forum Contributor
    Join Date
    04-02-2013
    Location
    West Palm beach, Fl
    MS-Off Ver
    Excel 2010
    Posts
    113

    Re: count and average numbers based off date, not worksheet data is in

    The avg. LOS means the average length of stay for the client at the detox. in the mini database I provided, the LOS can be found in column N, and is determined by subtracting the clients discharge date from their admission date. In regards to the criteria for the AMAs, I only want the average LOS for clients who leave against medical advice (AMA). if you check the formula in the "what it currently looks like" table under the AMA tab, the formula should explain what I am currently doing to achieve the avg. LOS for each month. However, that's not exactly what my constituents want. They want the AMAs to be counted in the month that they happen, but my database is created based off of when a client is admitted, so sometimes, a client will AMA in a month other than the month they are admitted, and my formulas, as they stand, don't account for that. Does that make sense?

  8. #8
    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: count and average numbers based off date, not worksheet data is in

    Yes it makes sense. In fact I already have the count by month AMAs worked out. The figures match expectations.

    I only want the average LOS for clients who leave against medical advice (AMA).
    I'm still a bit 'foggy' on how to derive those averages. I applied some temporary averaging formulas to length of stay AMA and cannot come up with the figures presented even with guessing. Is there any chance those expected figures are typos" or include non-AMAs ?
    Last edited by FlameRetired; 05-08-2015 at 01:50 PM.

  9. #9
    Forum Contributor
    Join Date
    04-02-2013
    Location
    West Palm beach, Fl
    MS-Off Ver
    Excel 2010
    Posts
    113

    Re: count and average numbers based off date, not worksheet data is in

    Typos are always possible! What I want are the averages for AMA's that are being counted for each month...I don't want it to just average the ama's that happen on a specific worksheet...

  10. #10
    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: count and average numbers based off date, not worksheet data is in

    Withdrawn by FR.

  11. #11
    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: count and average numbers based off date, not worksheet data is in

    Edit I've had some time to rethink this one. Please see my post that follows this one.
    OK I think it's finished. LOL!

    In the AMAs sheet there is a set of lookup tables. They extract and filter relevant columns from each of the sheets. They are all variations on a base formula
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    I retained "AMA" as an error check in the formula even though all of the DOD dates were AMA. I didn't know if your real life data followed that pattern. I also included an AMA lookup table as a cross check as I was building the formulas. Those can be deleted without affecting the formulas.

    In J5 and filled across to L5 this for the monthly counts including the look-backs.
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    In J6 and filled across to L6 for the average days by month including the look-backs.
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    The file is attached.

    Edit BTW: You mentioned size concerns above. These lookup tables include liberal use of the INDIRECT function. INDIRECT is volatile. This means that whenever you edit your workbook.....whether it directly affects the lookup tables or not.......INDIRECT is going to recalculate and each formula dependent....directly or indirectly.......upon those lookups is going to recalculate, too. If this becomes problematic (slow workbook) you may have to resort to directly referencing each monthly sheet in the lookup table or directly referencing each monthly sheet in the final formulas.........Ugh! and a real pain to edit!
    Attached Files Attached Files
    Last edited by FlameRetired; 05-10-2015 at 10:00 PM.

  12. #12
    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: count and average numbers based off date, not worksheet data is in

    This is simpler. If you have some control over your data rather referring to and across each monthly summary sheet use a common data table as source data for all summary sheets including the AMAs sheet.

    I made a 'data dump' table in 'Main Data' in the attached to demonstrate.

    Then the following approach eliminates the need for the lookup tables I proposed earlier, look-backs across multiple sheets and avoids an excess of INDIRECT function calls.

    For the counts in J4:L4 of AMAs this formula:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    and for the averages in J5:L5 this formula:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Additionally if your data in the monthly summary sheets are not already derived from a source table such as 'Main Data' you could also exploit your data source in the following way. Try this array-entered formula in B4 of each monthly summary sheet and fill down and across to U11.
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Array enter means the formula must be committed by simultaneously pressing and holding down Ctrl and Shift while hitting Enter.

    Hope this helps.

    The file is attached.
    Attached Files Attached Files
    Last edited by FlameRetired; 05-10-2015 at 09:58 PM.

  13. #13
    Forum Contributor
    Join Date
    04-02-2013
    Location
    West Palm beach, Fl
    MS-Off Ver
    Excel 2010
    Posts
    113

    Re: count and average numbers based off date, not worksheet data is in

    Thank you for the response. I will take a look at it now! I haven't been able to get back online until this morning!

  14. #14
    Forum Contributor
    Join Date
    04-02-2013
    Location
    West Palm beach, Fl
    MS-Off Ver
    Excel 2010
    Posts
    113

    Re: count and average numbers based off date, not worksheet data is in

    Yea, I was hoping to avoid a data dump, but if it's going to be more efficient then the volatile formulas you mentioned, then perhaps it's my best bet. So, do you have an array formula that could auto-populate the data dump instead of the monthly worksheets (backwards from what you so graciously provided)? The monthly worksheets are updated by a different department. I am actually only responsible for the AMA worksheet, as well as other worksheets with similar purposes. Otherwise, your solution for the AMA worksheet works brilliantly!

  15. #15
    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: count and average numbers based off date, not worksheet data is in

    So, do you have an array formula that could auto-populate the data dump instead of the monthly worksheets (backwards from what you so graciously provided)? The monthly worksheets are updated by a different department. I am actually only responsible for the AMA worksheet, as well as other worksheets with similar purposes.
    Yes I could do a formula that would do the data dump (the backwards way you mention), but I cannot think of a way to do that without excessive use of INDIRECT function calls again. Once such a 'dump' is done if you could copy / paste values in that dump (reserving one row of formula for additional 'dumps') then all of those INDIRECTs are no longer an issue, but I can't help wondering if this wouldn't be a royal pain.

    I am not VBA proficient, but I can call for help. If a VBA (macro) solution was created you could refresh/update these data dumps at will without all the fuss and resource load of any formulas I could provide. If you would like to look into this I will 'Call in the Cavalry'. We've got experts.

  16. #16
    Forum Contributor
    Join Date
    04-02-2013
    Location
    West Palm beach, Fl
    MS-Off Ver
    Excel 2010
    Posts
    113

    Re: count and average numbers based off date, not worksheet data is in

    You really have been exceptionally helpful! I appreciate that fact, considering this is strictly done out of the kindness of your heart! UM, I've done the cut/paste data dump option, so if it's not to much trouble, maybe the VBA route might be an option if it's not too complicated? :-)

  17. #17
    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: count and average numbers based off date, not worksheet data is in

    I'll Call in the Cavalry.

    Edit: Done.
    Last edited by FlameRetired; 05-11-2015 at 05:05 PM.

  18. #18
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,425

    Re: count and average numbers based off date, not worksheet data is in

    OK, late entry. And, with all respect to FR for the effort he has put in, it is ALWAYS a PitA to analyse data that is spread across multiple sheets. As FR has said, INDIRECT is volatile so will very likely cause performance issues. And complex Array Formulae will just add to the mix. Without using INDIRECT, the solution is not scalable as you will need to have specific formulae for each month column.

    So, if this has not been suggested already, why not ditch the idea of having separate sheets for each month and just have one sheet with all the patient data? You can then convert the data to a Structured Table. This will manage the ranges, it will copy formulae, formatting, Conditional Formatting, and Data Validation to each new row. More important, it will allow you to sort the data, filter the data, and Pivot the data. You could then perhaps have a Helper column that determines the month to use for the AMA calculation; that is, if month(DOA)<>month(DOD), use the month(DOD) for your calculation.

    A life much simpler ... but not worth pursuing here if that's not something you can live with.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  19. #19
    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: count and average numbers based off date, not worksheet data is in

    Quote Originally Posted by TMS View Post

    ..........So, if this has not been suggested already, why not ditch the idea of having separate sheets for each month and just have one sheet with all the patient data? ............

    Regards, TMS
    That was the direction I was trying demonstrate in post #12. OP indicates they inherit this workbook with all those sheets, and ditching the sheets doesn't appear to be an option.

    As formula wise this is a major PitA is there a macro workaround that would sidestep performance issues etc. and accomplish what you are describing? They have their own assigned summary sheets to add to the workbook.

  20. #20
    Forum Contributor
    Join Date
    04-02-2013
    Location
    West Palm beach, Fl
    MS-Off Ver
    Excel 2010
    Posts
    113

    Re: count and average numbers based off date, not worksheet data is in

    I really enjoy the thought of consolidating all of the data into one worksheet, and operating my summary sheets from just that one source, I just don't know if the folks who update the data, will be comfortable with that setup. Ok, the problem with the one worksheet approach, is that the person who keeps the information up-to-date and accurate will need to be able to modify entries quite frequently, as the information changes as the client's stay changes. Would a user form be possible to add/modify/remove data from the data dump? That might make the data entry portion of the process simple to understand and easy to achieve, which is very important for this particular group of people! Or, as the very helpful FlameRetired has inquired, some sort of VBA code that will bypass the volatile nature of the indirect formulas, but still allow for the current setup?

  21. #21
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,425

    Re: count and average numbers based off date, not worksheet data is in

    OK, have a look at the attached updated workbook. Rather than feed the monthly worksheets from the Data Dump, I have provided a button and code to consolidate the monthly data into a single worksheet, "Consolidated Data". The AMAs worksheet then bases its calculations on the Consolidated Data worksheet.

    I have used SUMPRODUCT rather than COUNTIFS and SUMIFS as I believe it is more flexible.

    I have also created several Dynamic Named Ranges which are all dependent on the data in column B.

    Note that the format of the Consolidated Data worksheet is identical to the monthly sheets, including the headings PLUS a calculated "AMA Applicable Date". The Consolidated Data worksheet must exist; it is not created in the code, although (in theory) it could be.


    Regards, TMS
    Attached Files Attached Files

  22. #22
    Forum Contributor
    Join Date
    04-02-2013
    Location
    West Palm beach, Fl
    MS-Off Ver
    Excel 2010
    Posts
    113

    Re: count and average numbers based off date, not worksheet data is in

    Ok, this looks like it will work! I just have to make sure I can get it to fit into the actual workbook. I will mark the thread as solved, but might have a question or two after the fact...is that ok? Anyway, thank you very much for your time on this TMS! I really appreciate it!

  23. #23
    Forum Contributor
    Join Date
    04-02-2013
    Location
    West Palm beach, Fl
    MS-Off Ver
    Excel 2010
    Posts
    113

    Re: count and average numbers based off date, not worksheet data is in

    Ok, I noticed that the code is specific to the consolidate data worksheet, and the AMA worksheet. I have two additional worksheets that will be setup the exact same way as the AMA worksheet, except that they are named, Relapse, and Elopements. There will be other worksheets as well that don't need the mods, and those are titled Lists, Index, Readmits, Detox Report, and Clinical Report. I don't know if that makes a difference in the code as I am only marginally familiar with VBA! Can you make any necessary modifications to the code based off of what I just provided?

  24. #24
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,425

    Re: count and average numbers based off date, not worksheet data is in

    You're welcome. Thanks for the rep.


    Replace the existing code with this:

    Please Login or Register  to view this content.

    Regards, TMS

  25. #25
    Forum Contributor
    Join Date
    04-02-2013
    Location
    West Palm beach, Fl
    MS-Off Ver
    Excel 2010
    Posts
    113

    Re: count and average numbers based off date, not worksheet data is in

    You rock! Thank you so much!

  26. #26
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,425

    Re: count and average numbers based off date, not worksheet data is in

    You're welcome.

  27. #27
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: count and average numbers based off date, not worksheet data is in

    Or.

    Please Login or Register  to view this content.



+ 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] VBA to replace new name of worksheets in formulas in newly copied worksheets
    By rikk1965 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 12-31-2013, 11:05 AM
  2. [SOLVED] Count and average formula needed to not count text field
    By excelteam777 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 07-07-2013, 05:30 PM
  3. Replies: 10
    Last Post: 04-25-2013, 06:12 PM
  4. Replies: 5
    Last Post: 01-31-2013, 12:55 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