Finding next and previous value of a column relative to a specific ID column

surendarmani

New Member
Joined
Mar 24, 2022
Messages
13
Office Version
  1. 2016
Platform
  1. Windows
Hi All,

I am a novice user learning formulas in excel. I am sure this following task is a no-brainer for all the experts here.

I've been trying to figure this out myself. Unfortunately, I didn't succeed in retrieving the expected outputs.

I have the ID, year, and GPA column in my dataset.

I am required to get 4 new columns: Previous year, previous_year_GPA, next year, next_year_GPA

Previous_year:
This is specific to the Year column.
I want the formula to look for the student ID column and see whether there is a (row-1) column specific to the ID, if yes print that previous row year in the"Previous_Year" column. If in case there is no (row-1) for the specific ID then print "No Previous data".

Previous_year_GPA:
Same as above. The only difference is the GPA column instead of the year column.

Next_year:
Here, we are looking to finding the (row+1)th Year and print the value in the "Next_Year" column. If row+1 data is not available for a specific ID then "No next data"

Next_year_GPA
Same as above but with GPA column instead of year column.

Can you please help with this?

Mr_Excel_Forum_Question_Previous_Next_Year_data_Retrieval.xlsx
ABCDEFGHIJKLMNO
1Actual DatasetExpected Dataset with next year data (row+1) & previous year data (row-1)
2IDNameYearGPAIDNameYearGPANext_YearNext_year_GPAPrevious_yearPrevious_year_GPA
3101John Smith20203.55101John Smith20203.5520213.25No previous dataNo previous data
4101John Smith20213.25101John Smith20213.252022420203.55
5101John Smith20224101John Smith20224No next dataNo next data20213.25
6156Robert Terry20212.67156Robert Terry20212.6720223.19No previous dataNo previous data
7156Robert Terry20223.19156Robert Terry20223.19No next dataNo next data20212.67
8187Lucas Derek20203.49187Lucas Derek20203.49No next dataNo next dataNo previous dataNo previous data
9199Sam Campbell20223.9199Sam Campbell20223.9No next dataNo next dataNo previous dataNo previous data
10212William Torres20203.520213.7No previous dataNo previous data
11212William Torres20213.7No next dataNo next data20203.5
12
13
Sheet1


Adding screenshot just in case some issues pop up with the above script.

1648137982768.png


Thanks
Surendar
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Hi & welcome to MrExcel.
How about
+Fluff 1.xlsm
ABCDEFGHIJKLMNO
1Actual DatasetExpected Dataset with next year data (row+1) & previous year data (row-1)
2IDNameYearGPAIDNameYearGPANext_YearNext_year_GPAPrevious_yearPrevious_year_GPA
3101John Smith20203.55101John Smith20203.5520213.25No previous dataNo previous data
4101John Smith20213.25101John Smith20213.252022420203.55
5101John Smith20224101John Smith20224No Next DataNo Next Data20213.25
6156Robert Terry20212.67156Robert Terry20212.6720223.19No previous dataNo previous data
7156Robert Terry20223.19156Robert Terry20223.19No Next DataNo Next Data20212.67
8187Lucas Derek20203.49187Lucas Derek20203.49No Next DataNo Next DataNo previous dataNo previous data
9199Sam Campbell20223.9199Sam Campbell20223.9No Next DataNo Next DataNo previous dataNo previous data
10212William Torres20203.5No Next DataNo Next DataNo previous dataNo previous data
11212William Torres20213.7No Next DataNo Next DataNo previous dataNo previous data
List
Cell Formulas
RangeFormula
L3:M11L3=IFERROR(1/(1/SUMIFS(C:C,$A:$A,$H3,$C:$C,$J3+1)),"No Next Data")
N3:O11N3=IFERROR(1/(1/SUMIFS(C:C,$A:$A,$H3,$C:$C,$J3-1)),"No previous data")
 
Upvote 0
It works like a charm, Ser. Thank you so much for helping me out on this one. Now, I am looking forward to learning and growing with this community.

Thanks again!

Surendar
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0
Also, one more question. What if I don't have the reference table ("Actual Dataset") and only have the "Expected Dataset with next year data (row+1) & previous year data (row-1)" table as my only table. How do I self-reference the cells in the ID, year and GPA columns to retrieve the value?

Mr_Excel_Forum_Question_Previous_Next_Year_data_Retrieval.xlsx
HIJKLMNO
1Expected Dataset with next year data (row+1) & previous year data (row-1)
2IDNameYearGPANext_YearNext_year_GPAPrevious_yearPrevious_year_GPA
3101John Smith20203.55
4101John Smith20213.25
5101John Smith20224
6156Robert Terry20212.67
7156Robert Terry20223.19
8187Lucas Derek20203.49
9199Sam Campbell20223.9
10212William Torres20203.5
11212William Torres20213.7
Sheet1


Thanks
Surendar
 
Upvote 0
Just change the H3 to A3 & the J3 to C3
 
Upvote 0
Apologies. I may have confused you! What if I have only one table like this and how would I populate the values in next year, previous year columns. The above formula worked perfectly for 2 tables.

Mr_Excel_Forum_Question_Previous_Next_Year_data_Retrieval.xlsx
ABCDEFGH
1Expected Dataset with next year data (row+1) & previous year data (row-1)
2IDNameYearGPANext_YearNext_year_GPAPrevious_yearPrevious_year_GPA
3101John Smith20203.55
4101John Smith20213.25
5101John Smith20224
6156Robert Terry20212.67
7156Robert Terry20223.19
8187Lucas Derek20203.49
9199Sam Campbell20223.9
10212William Torres20203.5
11212William Torres20213.7
Sheet1


Thanks
Surendar
 
Upvote 0
I don't think the previous formula is valid for the recent scenario since there is no lookup ID column to validate that the specific year and gpa belonged to that specific ID. Can you please help me with this one?

Thanks
Surendar
 
Upvote 0
Did you try the original formula with the changes I suggested?
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,964
Members
452,371
Latest member
Frana

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top