+ Reply to Thread
Results 1 to 15 of 15

Retrieve nearest value and titles from sheet data

  1. #1
    Registered User
    Join Date
    08-28-2013
    Location
    Pakistan
    MS-Off Ver
    Excel 2019
    Posts
    41

    Post Retrieve nearest value and titles from sheet data

    I need to retrieve nearest Value from Sheet to based on matching grades and then need to pull column titles of nearest values which are different as per value pulled.

    query mentioned in attached file.
    I have tried using Index, match, if and vlookup but not able to pull required result. help required.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Retrieve nearest value and titles from sheet data

    Please explain why the results needs to be:

    Result to be required
    Basic Stage Year
    30.240 Stage2 Y1 Q1
    27.450 Stage4 Y5 Q2
    23.867 Stage4 Y2 Q3
    21.724 Stage4 Y4

    Where (in which cells do we find those values) and why (the reason)?

    What is the logic behinds results.
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  3. #3
    Registered User
    Join Date
    07-08-2004
    Posts
    18

    Re: Retrieve nearest value and titles from sheet data

    Maybe like the attached.

    Array formula to return Basic in E4: INDEX(d,MATCH(A4,Sheet2!$A$3:$A$11,0),MATCH(MIN(ABS(Sheet2!B3:AZ3-C4)),ABS(Sheet2!B3:AZ3-C4),0))
    where d = Sheet2!$B$3:$AZ$11.

    Array formula to return Stage in F4: "Stage"&INT((MATCH(MIN(ABS(Sheet2!B3:AZ3-C4)),ABS(Sheet2!B3:AZ3-C4),0)-1)/5+1)

    Array formula to return Year in G4: INDEX(Sheet2!$B$2:$AZ$2,MATCH(MIN(ABS(Sheet2!B3:AZ3-C4)),ABS(Sheet2!B3:AZ3-C4),0))


    Array formulas must be entered by holding down Ctrl and Shift before pressing Enter.
    Attached Files Attached Files
    Last edited by dkhanknu; 04-02-2017 at 04:16 AM. Reason: Request from moderator

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,647

    Re: Retrieve nearest value and titles from sheet data

    @dkhanknu - sorry for off-topic interjection:

    Although there is no official rule regarding this behaviour, we request that wherever possible both the question AND the answer be provided in substantive detail here within the thread. An attached workbook is an excellent aid for posing a question and offering a solution, but solely doing that with no in thread explanation makes it difficult for researchers to understand or consider the Q & A of this thread without downloading what may be a pointless doc to them, if they can do that at all. Doing that also hides the content from search engines so others may never benefit from this.

    I'm sure you understand, and we look forward to seeing you post your formulas/macros in your posts for the searching benefit of all.

    Thanks again for all your hard work here!
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  5. #5
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,000

    Re: Retrieve nearest value and titles from sheet data

    Three questions:

    1. Are the data under Stage XX to be included? If so, are they Year 0, or something else?

    2. How can Year 5 be an expected answer (cell G5), when it doesn't appear in your data on the second sheet?

    3 (most importantly..) In your example, the you were looking for results for MI, MI-A, M-II, M-II-A, etc which are in EXACTLY the same order as they appear on the data sheet. Is that ALWAYS the case, or can you sometimes have M-II, M-I-A, M-III, or whatever in sheet 1 A4, A5, A6, etc....??
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

  6. #6
    Registered User
    Join Date
    08-28-2013
    Location
    Pakistan
    MS-Off Ver
    Excel 2019
    Posts
    41

    Re: Retrieve nearest value and titles from sheet data

    Thanks for reply
    Q1 to Q3 just stands for question, sorry i didn't mentioned that, the values that are put under titles Basic, Stage and Year are the required values and formula is required their, its like a HR sheet to check which staff is having what stage of payroll

  7. #7
    Registered User
    Join Date
    08-28-2013
    Location
    Pakistan
    MS-Off Ver
    Excel 2019
    Posts
    41

    Re: Retrieve nearest value and titles from sheet data

    Yes Data for Stage XX need to be included as it is actually Year 5
    The Data Sheet is basically a Year wise calculation of payroll that is increasing each year with a specific percentage, so the Stage Column is basically Y5 or Year5, and on each Y5 the incremental value % changes for next Y1 or Year1 as per current value of Stage or Y5
    Yes Grades will remain constant as these are Departmental wise, They are not going to change

  8. #8
    Registered User
    Join Date
    08-28-2013
    Location
    Pakistan
    MS-Off Ver
    Excel 2019
    Posts
    41

    Re: Retrieve nearest value and titles from sheet data

    Thanks for the formula dkhanknu

    it worked perfectly as required, one thing more i need to confirm as it came up when Glenn Kennedy asked the question, if the grade sorting order is changed then will this formula still work as i was locking the range to match and you made it simple with not locking the range for each row.
    INDEX(d,MATCH(A4,Sheet2!$A$3:$A$11,0),MATCH(MIN(ABS(Sheet2!B3:AZ3-C4)),ABS(Sheet2!B3:AZ3-C4),0))
    where d = Sheet2!$B$3:$AZ$11.


    and i just changed the formula to convert Stage to Y5
    IF(LEFT(INDEX(Sheet2!$B$2:$AZ$2,MATCH(MIN(ABS(Sheet2!B3:AZ3-C4)),ABS(Sheet2!B3:AZ3-C4),0)),1)="S","Y5",INDEX(Sheet2!$B$2:$AZ$2,MATCH(MIN(ABS(Sheet2!B3:AZ3-C4)),ABS(Sheet2!B3:AZ3-C4),0)))

    and Ctrl+Shift+Enter is required for each formula for array

  9. #9
    Registered User
    Join Date
    08-28-2013
    Location
    Pakistan
    MS-Off Ver
    Excel 2019
    Posts
    41

    Re: Retrieve nearest value and titles from sheet data

    I understand that AliGW, i'll try to keep that in mind in my future posts, thanks for the reminder.

  10. #10
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,647

    Re: Retrieve nearest value and titles from sheet data

    The comment was relating to post #3 in the thread, which has now been amended with more detail, and not yours.

  11. #11
    Registered User
    Join Date
    08-28-2013
    Location
    Pakistan
    MS-Off Ver
    Excel 2019
    Posts
    41

    Re: Retrieve nearest value and titles from sheet data

    @dkhanknu question of @Glenn Kennedy was valid as your formula is not valid when Grade value order is changed.

    results with different grades same order
    Without Sorting Order.JPG

    results with same grades
    Same Grade.JPG

    results with different grades different order
    With different order.JPG

    so the results are not correct as we are using ABS on same row where grades are matched as a sorted order
    need to update match string to get correct results.

  12. #12
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,000

    Re: Retrieve nearest value and titles from sheet data

    This array formula addresses the issue at Q3 in my comments at Post 5. However, you did not answer Q 1 and 2, so i can't do any more. However, if the column headed stage is supposed to be year 5, why does it occur at the BEGINNING of the Yr1, Yr 2, Yr3 sequence and not at the END, i your raw data.

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by Glenn Kennedy; 04-03-2017 at 02:23 AM. Reason: Simplified the offset function

  13. #13
    Registered User
    Join Date
    08-28-2013
    Location
    Pakistan
    MS-Off Ver
    Excel 2019
    Posts
    41

    Re: Retrieve nearest value and titles from sheet data

    I am sorry if I was not clear,
    Stage is actually Y5 and at the same time begining of new percentage, so Everytime on Y5 it restarts from Y1 as new pay scale.
    So if a staff is reached on stage7 that means that person actually worked for about 35 years that is a separate calculation not included in this post as not require

  14. #14
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,000

    Re: Retrieve nearest value and titles from sheet data

    Finalised.... I hope !
    Attached Files Attached Files

  15. #15
    Registered User
    Join Date
    08-28-2013
    Location
    Pakistan
    MS-Off Ver
    Excel 2019
    Posts
    41

    Re: Retrieve nearest value and titles from sheet data

    Thanks for the help, really appreciate it, it is working fine now, it must be the OFFSET that made it work correctly.

    for values
    =IFERROR(INDEX(Sheet2!$B$3:$AZ$11,MATCH(A4,Sheet2!$A$3:$A$11,0),MATCH(MIN(ABS(OFFSET(INDEX(Sheet2!$A$3:$A$11,MATCH(A4,Sheet2!$A$3:$A$11,0)),,1,,51)-C4)),ABS(OFFSET(INDEX(Sheet2!$A$3:$A$11,MATCH(A4,Sheet2!$A$3:$A$11,0)),,1,,51)-C4),0)),"")

    for Year Title
    =IFERROR(IF(LEFT(INDEX(Sheet2!$B$2:$AZ$2,MATCH(MIN(ABS(OFFSET(INDEX(Sheet2!$A$3:$A$11,MATCH(A4,Sheet2!$A$3:$A$11,0)),,1,,51)-C4)),ABS(OFFSET(INDEX(Sheet2!$A$3:$A$11,MATCH(A4,Sheet2!$A$3:$A$11,0)),,1,,51)-C4),0)),5)="Stage","Y5",INDEX(Sheet2!$B$2:$AZ$2,MATCH(MIN(ABS(OFFSET(INDEX(Sheet2!$A$3:$A$11,MATCH(A4,Sheet2!$A$3:$A$11,0)),,1,,51)-C4)),ABS(OFFSET(INDEX(Sheet2!$A$3:$A$11,MATCH(A4,Sheet2!$A$3:$A$11,0)),,1,,51)-C4),0))),"")

    for Stage Title
    =IFERROR("Stage"&INT(MATCH(MIN(ABS(OFFSET(INDEX(Sheet2!$A$3:$A$11,MATCH(A4,Sheet2!$A$3:$A$11,0)),,1,,51)-C4)),ABS(OFFSET(INDEX(Sheet2!$A$3:$A$11,MATCH(A4,Sheet2!$A$3:$A$11,0)),,1,,51)-C4),0)/5)+1,"")

+ 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. Replies: 9
    Last Post: 11-07-2014, 07:10 AM
  2. Taking titles from a sheet that has data in
    By nappy1001 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 02-05-2014, 03:11 PM
  3. Replies: 9
    Last Post: 04-01-2012, 08:41 PM
  4. Retrieve data from other sheet
    By nvsanilkumar in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-27-2011, 07:43 AM
  5. Retrieve data from another sheet
    By ghazani7 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-05-2007, 03:03 AM
  6. Sheet titles from the colomn data
    By OK_pal in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-09-2006, 07:34 AM
  7. Retrieve Data from one sheet to another
    By karstens in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 07-11-2006, 03:49 PM

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