+ Reply to Thread
Results 1 to 8 of 8

Copy Rows and Expand Dataset

  1. #1
    Registered User
    Join Date
    02-08-2010
    Location
    Boston, Massachusetts
    MS-Off Ver
    Excel 2007
    Posts
    28

    Copy Rows and Expand Dataset

    Hi,

    I am trying to expand my dataset by copying rows and changing one cell within each row when it is copied.

    In Column M there is an ID. The ID repeats on many rows because it has data on many different dates (Column O)

    In general, the dates are generally at the end of a quarter. They are usually March 31st, June 30, Sep 30, Dec. 31st. There is usually not data in between, so I need to fill the data in between the quarters. Sometimes, the date could be August, or July, or any month really.

    So lets say the ID is 1 and the Date is Mar 31st. I would want to copy the row twice. One time I would copy it Feb 28th and the other time to Jan 31st.

    However, sometimes there is already a row with ID 1 and Date Feb 28th. If this is the case, I would not want copy the row this time.

    Also, when I speak about dates, all that really matters is the year and the month, so I can reformat the dates to make that easier.

    I have attached a sample file with two tabs, Input and Output. In the output, a copied row is indicated by the green color. Please note the instance when there are NOT two green rows above a white row. This occurs because this row already appears.

    Any help you guys could give me would be greatly appreciated. I am really really stuck and this would save my life. Please let me now if you could help.

    Sincerely,

    Michael

  2. #2
    Registered User
    Join Date
    02-08-2010
    Location
    Boston, Massachusetts
    MS-Off Ver
    Excel 2007
    Posts
    28

    Re: Copy Rows and Expand Dataset

    here is the attachment
    Attached Files Attached Files

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

    Re: Copy Rows and Expand Dataset

    1) Is it OK to sort the data prior to copying so the like items are next to each other? This would make the coding simpler, and the resulting listing might make more sense.

    2) In the case of item #100000876702, should the copy ONLY be for the one that ended on 3/31 and NOT copy the one from 2/28?

    3) Those bogus formulas in the sample data, those aren't relevant right now, right?
    _________________
    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!)

  4. #4
    Registered User
    Join Date
    02-08-2010
    Location
    Boston, Massachusetts
    MS-Off Ver
    Excel 2007
    Posts
    28

    Re: Copy Rows and Expand Dataset

    It is definitely okay to sort. I would add a counter though so I could resort back to the order its in right now and so it would simply copy the counter as well. This isn't crucial though.

    I guess I made a mistake for the 2/28/2003 entry. It should first check whether there is one in January. There is, so it shouldn't make a January entry. Then it should check if there is a December 2002 entry. There isn't in this dataset, so then it should copy for December. Ideally, though, the 2/28/2003 data would be copied to January instead of the March 2003 data. This way the it gets the data closer to it chronologically. I guess your sorting idea would solve that problem. (Did that make sense)

    And yes the formulas are not important (meant to delete them). Thank you so so much for helping.

    As a side note, one thing I am worried about is this might create a dataset greater than 1M rows. Is there a solution other than splitting the set into two/three?

    Thank you so much for the help

    Michael
    Last edited by mbuckley56; 02-14-2010 at 09:50 PM. Reason: mistype

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

    Re: Copy Rows and Expand Dataset

    Well, it sounds like your query has changed a little, so let's clarify:
    1. Data sorted is OK. (Good)
    2. Starting at the BOTTOM of the dataset we check the first column M value. If the date listed is the last date of a quarter, then check the row above...:
      1. if the column M value is the same and the end of month prior, check the next row above and see if it's same value and end of 2nd month prior. If yes, then move on
      2. If either row is NOT the same value and/or month(s) prior, copy upward to get them
      3. Each time no more than two months are being added, we're not going backward in time indefinitely, just the current quarter
    3. If the date listed is NOT the end of a quarter, skip it


    Quote Originally Posted by mbuckley56 View Post
    one thing I am worried about is this might create a dataset greater than 1M rows. Is there a solution other than splitting the set into two/three?
    That is a concern. Perhaps you should sort the data, then run this "expansion" tool on no more than 333k of data at a time.

  6. #6
    Registered User
    Join Date
    02-08-2010
    Location
    Boston, Massachusetts
    MS-Off Ver
    Excel 2007
    Posts
    28

    Re: Copy Rows and Expand Dataset

    Okay let me alter that procedure slightly.


    1. Data sorted is OK. (Good)
    2. Starting at the BOTTOM of the dataset we check the first column M value. should check rows even if its not at the end of a quarter, because this is not ALWAYS a requirement. sorry for the confusion
    3. Check the row above if the column M value is the same and the end of month prior, check the next row above and see if it's same value and end of 2nd month prior. If yes, then move on
    If either row is NOT the same value and/or month(s) prior, copy upward to get them
    "Each time no more than two months are being added, we're not going backward in time indefinitely, just the current quarter." Is there anyway we could keep going until: first check M value. If its not the same don't keep going. If it is the same, check the date. Keep going until you reach that date (but don't overwrite). I am pretty sure this will entail never having more than two months, but I will need to verify my dataset. Seems better to have it this way though if its possible, to be sure.

    To clarify the main goal, its basically to fill in all of the months without overwriting any data thats already there. (But not every ID will have the same start end end points. I just want to fill in the data between quarters)

    Does that make sense or should I clarify?

    Thanks,
    Michael

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

    Re: Copy Rows and Expand Dataset

    Time to redo your sample sheet. This time expand it to fully demonstrate examples of ALL the scenarios that have to be dealt with. Don't dumb it down, make sure the data is complicated enough to show all the hurdles.

    Then, of course, the desired results.

    You don't have to make it 26 columns wide, just make sure we know which exact columns to evaluate, we'll do "row" copies so it will always get all the columns.

  8. #8
    Registered User
    Join Date
    02-08-2010
    Location
    Boston, Massachusetts
    MS-Off Ver
    Excel 2007
    Posts
    28

    Re: Copy Rows and Expand Dataset

    I am really sorry but I have to change the instructions once again. If you have already done some work to do this, then please let me know if it is too difficult to alter at this point. I am really so sorry if this causes any inconvenience.

    It should ALWAYS try and copy ONLY at most 2. There will never be an instance when it needs to copy more than 2, and it should always attempt. For instance,

    Id date

    1 feb 09
    2 mar 09

    output:

    1 dec 08
    1 jan 09
    1 feb 09
    2 jan 09
    2 feb 09
    2 mar 09

    If it is too difficult, then we could definitely shortcut a fix, by labeling original rows with an indicator. Then we could see if how many new rows lie above each original row. Just a thought

    Please tell me if my sample data set is too large.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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