See if this helps - the idea is you need your function to return the position you want that item in. ... sort lines of tRawData numeric by termOrderSort(each) ... function termOrderSort pTerm return itemOffset(item 1 of pTerm, lSortOrder) end termOrderSort