Update the Sortby Function

Use a generic sortby that can sort using sample_data or measurements.
Add a unit test to test each of those.