FirstSortedValue is an aggregation function you can use in the script to do just this, grouped by Customer, in your example. The example in the QV Desktop help for that function is very similar to what you are doing.

As with all aggregating in the script, any expression not in the GROUP BY requires some aggregation function.

An alternative would be breaking it into multiple steps, like loading the original table, then doing a resident load with ORDER BY and use an inter record functions like Peek to create an indicator or flag on the latest row per customer. Lastly you can do a resident load of that table WHERE the indicator or flag value is for the latest row, or just inner join an inline table containing only the desired flag or indicator value.