EMoe said:
JoeU, I tried your formula, and it worked out fine. Also in the process
of trying to figure this out, I came up with this, which also worked for
me. Formula:
=IF(AND(W44>0.5,W44<38.5),"Empty",IF(AND(W44>38.5,W44<39.5),"Low",IF(AND(W44>39.5,W44<40.5),"Ok",IF(W44>40.5,"Full",IF(W44<0.5,"")))))
In your original posting, you asked for simpler ways to do things.
There are several things that can be improved (or corrected) in the
above.
1. You repeatedly make the mistake of using "<" of ">" instead of "<="
or ">=", as I and others noted previously. That creates
discontinuities -- values within the range of interest that are not
covered. I doubt that you are doing that intentionally. For example,
in the above, you might be surprised to get FALSE instead of "empty" or
"low" when W44 is exactly 38.5. Similarly, you will get FALSE when W44
is exactly 39.5, 40.5 and 0.5.
2. You can avoid most uses of AND() by ordering the tests from
low-to-high values, as I did. So the above could be written more
concisely as:
=if(W44<=0.5, "", if(W44<38.5, "empty", if(W44<39.5, "low",
if(W44<40.5, "ok", "full"))))
Note that the second test, for example, is implicitly the same as
AND(W44>0.5,W44<38.5) because we get there only if W44<=0.5 is not
true, ergo W44>0.5 is true. (By the way, for symmetry and consistency,
I suspect you want to W44<0.5, not W44<=0.5.)
3. Beware of nesting functions too deeply. Excel has a nesting limit
of 7. You have a nesting level of 4; my approach in #2 has one less
nesting level. That is why the use of LOOKUP() is appealing in you
case. By the way, my previous use of LOOKUP() was unnecessarily
complicated. (I started with one idea, ended up with another, but
failed to make simplifying adjustments.) In you latest case, you could
write:
=if(W44<=0.5, "", lookup(W44, {0.5,38.5,39.5,40.5}, {"empty", "low",
"ok", "full"}))
LOOKUP() matches the largest value less than or equal to W44.