Extract unique values based on multiple criteria