+ Reply to Thread
Results 1 to 17 of 17

Retrieve Code From Prior Term Based on ID

  1. #1
    Registered User
    Join Date
    12-08-2017
    Location
    United States
    MS-Off Ver
    2016
    Posts
    53

    Retrieve Code From Prior Term Based on ID

    Hello,

    I have a list of IDs that each have a code based on the term date. This code may change depending on the term. Is there an easy way to determine what the code was the prior most recent term? For example, for 9/1/2014 the prior term to check would be 2/1/2014. The formula would retrieve whatever the code was in the prior term. From there, I could easily determine if the code is the same, different, or there is no data for that ID in the previous term (even if there may be data for that ID in an older term; I only care about the last one prior) I ordered the terms by numbers as I thought that may help. Term 1 should be ignored as I only kept it so I could get data for Term 2. I assume it might be something with Index and Match?

    Any suggestions would be highly appreciated.
    Attached Files Attached Files
    Last edited by Dord25; 05-24-2018 at 06:46 PM.

  2. #2
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Cool Re: Retrieve Code From Prior Term Based on ID

    is that what you want?

    done with PivotTable (or I misunderstood)
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    12-08-2017
    Location
    United States
    MS-Off Ver
    2016
    Posts
    53

    Re: Retrieve Code From Prior Term Based on ID

    Thank you for the help. What I meant is that to get the code associated with the ID for the previous term. So for example, an ID might have a code of TM for 9/1/2014 and I want to find out what the was the code associated with the ID for 2/1/2014, which is the prior term right before it. Likewise, if the ID exists for 2/1/2015, I would want to return what the code was for the ID for 9/1/2014, the prior term. And if the ID exists for 9/1/2015, return the code associated with the ID for 2/1/2015, and so on and so forth. I created "Term Code Based on Order" to help. If the term code is 4, the prior term has a code of 3, etc.

  4. #4
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Cool Re: Retrieve Code From Prior Term Based on ID

    something like this one?

    if not, post any example how it should be

  5. #5
    Registered User
    Join Date
    12-08-2017
    Location
    United States
    MS-Off Ver
    2016
    Posts
    53

    Re: Retrieve Code From Prior Term Based on ID

    Thank you, but not exactly. For example, let's say I have the following row:

    Term Date Term Code Based on Order Code ID Code During Prior Term
    09/01/14 2 PE 2073093 LA

    The first four data cells are given to me, so the code PE (column 3) is associated with ID 2073093 for "Term Code Based on Order" 2 and "Term Date" 9/1/2014. I want to find what code is associated with the ID 2073093 for the prior term (defined as "Term Date" 02/1/2014 or "Term Code Based on Order" of 1). In this example for this ID, the "Code During Prior Term" was "LA", but it could be "PE", or many other codes. If no match is found for the prior term for the ID, there is a blank. Even if that ID can be found several terms back, all that I care about is the prior term nearest in time to the one listed on the row.

  6. #6
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2404
    Posts
    13,406

    Re: Retrieve Code From Prior Term Based on ID

    I am confused.

    Where would you like the output?

    What role do columns K:L have in the upload?

    How are we to know what ID to be querying?
    Dave

  7. #7
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Cool Re: Retrieve Code From Prior Term Based on ID

    there are many duplicates and more than one which fit your term.
    I didn't add ID because this is too long but check if this is what you want

    done with PowerQuery

    edit:
    I forgot as usual
    short desc.: Grouped, removed duplicates
    Last edited by sandy666; 05-25-2018 at 11:33 PM.

  8. #8
    Registered User
    Join Date
    05-25-2018
    Location
    Sydney
    MS-Off Ver
    2013
    Posts
    14

    Re: Retrieve Code From Prior Term Based on ID

    My solution is based on two formulas.

    Enter the following formula into E8252 (start of 2nd term) and fill it down

    =COUNTIFS($D$2:D8252,D8252)

    Enter the following array formula into F8252 using Shift + Ctrl + Enter and copy it down

    =IFERROR(INDEX($C$2:$C$41367,MATCH(1,((E8252-1)=$E$2:$E$41367)*(D8252=$D$2:$D$41367),0)),"")


    I ran a pivottable and show the result for 3000945972 below. Reference Previous Term Based on ID.PNG


    Kind regards

    Saba

  9. #9
    Registered User
    Join Date
    05-25-2018
    Location
    Sydney
    MS-Off Ver
    2013
    Posts
    14

    Re: Retrieve Code From Prior Term Based on ID

    I have the solution workbook and do not know how to load it.

  10. #10
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Retrieve Code From Prior Term Based on ID

    To attach an Excel file to your post,
    • desensitize data
    • click Go Advanced,
    • scroll down until you see Manage Attachments,
    • click that and select Browse,
    • select your file and click Open,
    • click Upload and you will see your attachment below Upload Files from a website
    • click Close this window,
    • click Submit reply

    After that you should see attachment in your post

  11. #11
    Registered User
    Join Date
    05-25-2018
    Location
    Sydney
    MS-Off Ver
    2013
    Posts
    14

    Re: Retrieve Code From Prior Term Based on ID

    Thank you Sandy.

    The solution workbook is attached.

    I had to zip the file as it is more than 1mb.

    Kind regards

    Saba
    Attached Files Attached Files

  12. #12
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Cool Re: Retrieve Code From Prior Term Based on ID

    You could save it as xlsb format instead of zip

  13. #13
    Registered User
    Join Date
    05-25-2018
    Location
    Sydney
    MS-Off Ver
    2013
    Posts
    14

    Re: Retrieve Code From Prior Term Based on ID

    Thank you! Sandy

    Xlsb file is attached.

    Kind regards

    Saba
    Attached Files Attached Files

  14. #14
    Registered User
    Join Date
    12-08-2017
    Location
    United States
    MS-Off Ver
    2016
    Posts
    53

    Re: Retrieve Code From Prior Term Based on ID

    FlameRetired--the output would be in column E. Columns K:L just show the numbers I used for the Vlookup.

    Saba--The issue with that formula is that it returns the code based on the last term where the id was found. So if the COUNTIF returns 3 for an ID, the formula will find the code for that ID when the COUNTIF was 2. However, this may be in one or more terms ago, when I am only looking to see if the ID had a code in the prior term, based on the order in column B.

    Luckily, I think I was able to solve it based on your formula, by using column B.
    =IFERROR(INDEX($C$2:$C$41367, MATCH(1, (D2=$D$2:$D$41367)*((B2-1)=$B$2:$B$41367),0)),"")

    It seems it was simpler than I thought. Thank you all for the help!

  15. #15
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Retrieve Code From Prior Term Based on ID

    Nice to see you resolve the problem

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

    Have a nice day

  16. #16
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2404
    Posts
    13,406

    Re: Retrieve Code From Prior Term Based on ID

    You are welcome. Glad you've got it resolved. Thanks for the feedback.

  17. #17
    Registered User
    Join Date
    05-25-2018
    Location
    Sydney
    MS-Off Ver
    2013
    Posts
    14

    Re: Retrieve Code From Prior Term Based on ID

    No problem.

    Happy to help.

    Kind regards

    Saba

+ 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] Code based on term
    By Billy Spivy in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 03-23-2018, 12:48 PM
  2. VBA code to retrieve value from combbox based on cell value
    By Joao Mbachi in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-21-2018, 09:49 AM
  3. Using activex control to retrieve data relevant to the term searched.
    By garyaddis1983 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-05-2015, 11:13 AM
  4. Calculating short term and long term moving average in VBA
    By ixthus in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-10-2013, 02:40 AM
  5. Search up/down from n'th term and retrieve value if minimum difference
    By scope951 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-26-2010, 07:16 AM
  6. COde for selecting second term...
    By skonduru in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-27-2009, 10:02 AM
  7. Replies: 1
    Last Post: 05-21-2009, 03:34 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