How to create condition based on a range?