If you're not experienced with code (and even if you are), it's best to steer clear of using custom code in InfoPath forms, lest you wind up with a maintenance nightmare.
qRules was created precisely for situations like these, and its SortTable command can have you sorting your table within minutes.