Calculating the rank of values