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
 
It worked for me.
+Fluff 1.xlsm
ABCDEFGH
1Expected Dataset with next year data (row+1) & previous year data (row-1)
2IDNameYearGPANext_YearNext_year_GPAPrevious_yearPrevious_year_GPA
3101John Smith20203.5520213.25No Next DataNo Next Data
4101John Smith20213.252022420213.25
5101John Smith20224No Next DataNo Next Data20224
6156Robert Terry20212.6720223.19No Next DataNo Next Data
7156Robert Terry20223.19No Next DataNo Next Data20223.19
8187Lucas Derek20203.49No Next DataNo Next DataNo Next DataNo Next Data
9199Sam Campbell20223.9No Next DataNo Next DataNo Next DataNo Next Data
10212William Torres20203.520213.7No Next DataNo Next Data
11212William Torres20213.7No Next DataNo Next Data20213.7
List
Cell Formulas
RangeFormula
E3:F11E3=IFERROR(1/(1/SUMIFS(C:C,$A:$A,$A3,$C:$C,$C3+1)),"No Next Data")
G3:H11G3=IFERROR(1/(1/SUMIFS(E:E,$A:$A,$A3,$C:$C,$C3-1)),"No Next Data")
 
Upvote 0

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
It's not working on this dataset that I am trying to populate these results. This is a large dataset with >13500 rows.


Active_UG_Students_with_GPA_by_Term_v3__with_sorting_edit_in_progress.xlsx
ABCDEFGH
1IDNAMEACADEMIC_PERIODGPAPREVIOUS_ACADEMIC_PERIODPREVIOUS_TERM_GPANEXT_ACADEMIC_PERIODNEXT_TERM_GPA
2101Student12019202.52941177No Previous DataNo Next Data
3101Student12020102.75No Previous DataNo Next Data
4101Student12021103.4No Previous DataNo Next Data
5101Student12021202.4No Previous DataNo Next Data
6102Student22021104.No Previous DataNo Next Data
7102Student22021204.No Previous DataNo Next Data
8102Student22022104.No Previous DataNo Next Data
9103Student32019203.No Previous DataNo Next Data
10103Student32020103.5No Previous DataNo Next Data
11104Student42019203.25No Previous DataNo Next Data
12104Student42020103.75No Previous DataNo Next Data
13104Student42021104.No Previous DataNo Next Data
14104Student42021203.5No Previous DataNo Next Data
15105Student52019201.75No Previous DataNo Next Data
Any_semesters_with_valid_GP (2
Cell Formulas
RangeFormula
E2:E15E2=IFERROR(1/(1/SUMIFS(C:C,$A:$A,$A2,$C:$C,$C2-1)),"No Previous Data")
H2:H15H2=IFERROR(1/(1/SUMIFS(F:F,$A:$A,$A2,$C:$C,$C2+1)),"No Next Data")
Named Ranges
NameRefers ToCells
'Any_semesters_with_valid_GP (2'!_FilterDatabase='Any_semesters_with_valid_GP (2'!$A$1:$H$13860H2:H15, E2:E15


But it worked fine with the previous dataset which had <15 rows.

Is there any specific reason the formula isn't working on this one?

Thanks
Surendar
 
Upvote 0
Is there any specific reason the formula isn't working on this one?
Yes. In your previous data you had years in col C, now you don't, so cannot simply add or subtract one from that value.
 
Upvote 0
Appreciate you looking into this and helping me to understand the issue. Is there any workaround to get the required next and previous row values for this kinda dataset?

Surendar
 
Upvote 0
Yes it's possible, but as it's now a significantly different question, it needs a new thread.
You will also need to explain what is considered the next & previous period.
 
Upvote 0
Yes it's possible, but as it's now a significantly different question, it needs a new thread.
You will also need to explain what is considered the next & previous period.
Sure, I will create a new thread then and explain the details there.

Thanks again
 
Upvote 0

Forum statistics

Threads
1,214,782
Messages
6,121,532
Members
449,037
Latest member
tmmotairi

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