+ Reply to Thread
Results 1 to 8 of 8

Filtering/deleting rows based on numerous individual index dates

  1. #1
    Registered User
    Join Date
    05-14-2017
    Location
    Scotland
    MS-Off Ver
    MS 2010
    Posts
    4

    Filtering/deleting rows based on numerous individual index dates

    For a research project I am trying to find out how often several hundred patients have been admitted to various hospital departments, and additional info like the type of discharges etc. For each department I have a spreadsheet covering all sorts of data from the late 90s to today (resulting in tens of thousands of rows in each spreadsheet, for a total of seven spreadsheets). However, for each patient I am only interested in a 2-year period after they have completed a certain treatment. The problem is that this period is different for each patient.

    I have cleaned up most of the mess, so the first column contains the unique patient ID (in each row, usually covering dozens to several hundred rows), the second column contains the individual admission dates. An additional spreadsheet contains the patient IDs in the first column, the index date in the second, and the end date of the follow-up period in the third column.

    Now I need to remove (or filter out) all rows in the spreadsheets that contain admission dates that fall outside the 2-year period. I know how to filter by date range with advanced filters across the whole spreadsheet, but after quite some time on Google and looking at tutorials I am still at a loss as to how to do this for different individual index dates for each patient. I have found out that a pivot table is supposed to help, but I don't know how to link such a table to my spreadsheet (or sheet) containing the data on individual follow-up periods, so excel checks the index date for each patient ID to filter out the rows containing dates that fall outside this period.

    If anyone could point me towards the right option in Excel, or any resource/tutorial to achieve this, that would be greatly appreciated

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Filtering/deleting rows based on numerous individual index dates

    When in doubt, add a helper column. For you, I'd add a formula that is doing the "within two years" test for one row.

    For instance, =IF(B2-A2<=720, "Within", "Outside")

    You get the idea.

    Now you have a column that is flagging each row for you in advance. Do your filtering and copying based on those values.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    05-14-2017
    Location
    Scotland
    MS-Off Ver
    MS 2010
    Posts
    4

    Re: Filtering/deleting rows based on numerous individual index dates

    Quote Originally Posted by JBeaucaire View Post
    When in doubt, add a helper column. For you, I'd add a formula that is doing the "within two years" test for one row.

    For instance, =IF(B2-A2<=720, "Within", "Outside")

    You get the idea.

    Now you have a column that is flagging each row for you in advance. Do your filtering and copying based on those values.
    Thanks for the reply. The way I understand it I would have to create another column in the actual spreadsheets with the data and insert the index dates - considering the number of rows for each patient varies (from a few dozen to several hundreds), it seems like I would have to copy the index dates over manually.

    Wouldn't creating that helper column take just as long as just deleting the unwanted rows by hand?

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Filtering/deleting rows based on numerous individual index dates

    Not all, assuming there is 100s or 1000s of rows.

    I'm just guessing based on the preliminary info you've provided.

    I can be more surgical in my idea looking at real sample (desensitized) data. Make sure there is just enough data to fully present and demonstrate your need.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

  5. #5
    Registered User
    Join Date
    05-14-2017
    Location
    Scotland
    MS-Off Ver
    MS 2010
    Posts
    4

    Re: Filtering/deleting rows based on numerous individual index dates

    I made up some data (the real one is on a secure server with remote access, and I'd be drawn and quartered if I tried to remove any of it ) and attached it to this post. It's just an example, the actual datasets are naturally much bigger.

    I could do what you described, i.e. make a new column next to the patient IDs, insert the index dates, then use the formula you posted, but because the number of rows per patient differ I would have to copy a number of cells with index dates, then add more, or take some out etc., and I think in that case I may as well remove the rows manually (highlight and delete them collectively from the first row to the index date, and then from the end of the follow-up period to the last row for the patient, not one by one, of course).

    So I was wondering whether there is a way to make Excel recognise the patient ID in the first column in Sheet2 (Admission data), go to Sheet1 (Index dates), check the follow-up period for that patient, and delete any rows for that patient in Sheet2 that fall outside that period. Alternatively I could of course copy the index data from Sheet1 somewhere into Sheet2, if that makes it easier.

    At least that's what I had in mind, maybe there's a better way to do it (or maybe it's not even possible at all)
    Attached Files Attached Files

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Filtering/deleting rows based on numerous individual index dates

    So, we are deleting all rows on Admission Data where the date in column B is outside the "range of dates" for that ID listed on sheet Index Dates, yes?

    If so, I think this is the formula you want:

    E2: =MEDIAN(INDEX('Index dates'!B:B,MATCH(A2,'Index dates'!A:A,0)),INDEX('Index dates'!C:C,MATCH(A2,'Index dates'!A:A,0)),B2)=B2

    ...copied down.

    Then filter column E for FALSE and delete all visible rows, or filter for TRUE to simply show the good entries and leave the bad ones there, but hidden.

  7. #7
    Registered User
    Join Date
    05-14-2017
    Location
    Scotland
    MS-Off Ver
    MS 2010
    Posts
    4

    Re: Filtering/deleting rows based on numerous individual index dates

    Sorry for the late reply, I just got time to try it out. First I thought it wasn't working properly (tons of dates within the follow-up were flagged as FALSE), then realised some of the dates in the Index sheet were formatted the wrong way. Fixed it and all is good now.

    BRILLIANT! Thanks a LOT for that, you saved me many hours of work

  8. #8
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Filtering/deleting rows based on numerous individual index dates

    As it appears you've reached a conclusion, I've marked this thread SOLVED for you.FYI, this is done through the Thread Tools located above the first post in this thread. Thanks.

+ 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. Consolidating Rows Based on Numerous Variables
    By pgwyther in forum Excel General
    Replies: 5
    Last Post: 07-10-2015, 12:20 PM
  2. Need a VBA for filtering and deleting rows. Easy task 4U + REP guaranteed!
    By Arty_1 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 02-24-2015, 08:58 AM
  3. [SOLVED] Filtering and deleting unwanted rows
    By joshag in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-25-2014, 01:59 PM
  4. Replies: 2
    Last Post: 08-19-2013, 06:00 AM
  5. Filtering / Deleting Rows with Defined Prefix ?!
    By eLearner in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-31-2011, 05:06 AM
  6. Deleting rows using complex(custom) filtering
    By djreklame in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-18-2011, 01:16 PM
  7. deleting individual cells so cell values will wrap around rows
    By fintan.mcloughlin in forum Excel General
    Replies: 0
    Last Post: 03-31-2009, 07:04 AM

Tags for this Thread

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