In this post, we will see how to resolve How to Link the trip based on condition and assign unique key?
Question:
I have a trip data where I have start date, end date, start location and end location. I need to generate a key for this data set.First, sort the data based on start date and then for every start and end date pair if the end location of previous row and start location of current row are same, assign same ID else assign new id. If date are different by default assign new ID.
This is the output I require. [For input just delete the Key column]
Best Answer:
You need another key to group withStart
and End Start
columns according your requirement (check if the current Location
is the same as previous End Location
). After that, use ngroup
to get the group number:Loc
:If you have better answer, please add a comment about this, thank you!
Source: Stackoverflow.com