Calculate balance based on sort order