简体   繁体   中英

IF statement, number less than X but greater than Y

Within my program I have a column(H) specifying hours:

(24.2, 23.5, 21.5, 25.0, 28.3, 23.1, 22.5, 17.9, 22.1, 16.2, 24.3, 23.8)  

this continues for 600 or so more rows.

Max hours = 36.88348
Min hours = 16.15569

I'm trying to categorise the hours into four different numbers to later use for more accurate data than averages:

0 = 16-20,  
1 = 21-25,  
2 = 26-30,  
3 = 31>.  

So far I have came to this solution:

=IF($H4>=31,3,IF($H4<=20,0,IF($H4>=21<=25,1,IF($H4>=26,2)))) 

This works apart from the 21-25($H4>=21<=25,1) .

If anybody could assist me, I believe it's something basic as my syntax.

更短:

=MATCH(H4,{0,21,26,31})-1

稍短:

=LOOKUP(H4,{0,21,26,31},{0,1,2,3})

尝试这个:-

=IF($H4>=31,3,IF($H4<=20,0,IF(AND($H4>=21,$H4<=25),1,IF($H4>=26,2))))

Just start with the lowest value and work up:

=IF($H4<=20,0,(IF($H4<=25,1,(IF($H4<=30,2,3)))))

以下应该工作:

=IF($H4>=31,3,IF($H4>=26,2,IF($H4>=21,1,IF($H4<21,0))))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM