using OR and AND and IF operators in a single excel formula

Dale van Dam 0 Reputation points
2026-11-25T23:37:00.6933333+00:00

Trying to assign "class" values (either 2, 4, 8, or 10) to a set of values with the following formula:

=IF(AND(E128>0,E128<350),2,0)*OR(AND(E128>350,E128<631),4,0)*OR(AND(E128>631,E128<1200),8,0)*OR((E128>1200),10,0)

returns expected values for values 0 to 350 and 350 to 631, but not for others. What am I missing?

Microsoft 365 and Office | Excel | For business | Windows
0 comments No comments

3 answers

Sort by: Most helpful
  1. Andreas Killer 143.6K Reputation points Volunteer Moderator
    2026-11-26T06:32:28.97+00:00

    Hi Dale,

    Another alternative using one input cell is to use HLOOKUP with a two-dimensional matrix. Look at the part of this formula enclosed in curly braces {}:

    =HLOOKUP(E128,{0,1,351,632,1201;0,2,4,8,10},2,TRUE)
    

    In the middle, you'll see a semicolon (;), which divides the matrix into two rows. The left part (first row) contains the values ​​being searched, and the right part (second row) contains the values ​​returned when a match is found. A match is found if the value in E128 is greater than or equal to the value in the matrix.

    This produces the same results as the IFS formula, but assumes that the value in E128 is only an integer.

    Andreas.

    Was this answer helpful?

    0 comments No comments

  2. Kai-Ex 2,665 Reputation points Microsoft External Staff Moderator
    2026-11-26T00:08:07.5533333+00:00

    Hi Dale van Dam ,

    In addition to the information provided by AI, you could try this formula:

    =IF(E128<=0,0,IF(E128<=350,2,IF(E128<=631,4,IF(E128<=1200,8,10))))

    I tested it, and the results follow the rules you described.

    Please review it and let me know if it does not work as expected.

    User's image

    Was this answer helpful?

    0 comments No comments

  3. AI answer

    2026-11-25T23:37:40.95+00:00

    Use an ordered IFS formula so that Excel returns the class associated with the first matching threshold:

    =IFS(E128<=0,0,E128<=350,2,E128<=631,4,E128<=1200,8,TRUE,10)
    

    IFS evaluates conditions from left to right and returns the value paired with the first TRUE condition, making it suitable for ordered classifications in Microsoft 365. The final TRUE,10 provides the default for anything above 1200. ^1^

    Boundary results

    This formula defines the boundaries explicitly:

    Value in E128 Result
    <= 0 0
    > 0 and <= 350 2
    > 350 and <= 631 4
    > 631 and <= 1200 8
    > 1200 10

    If 0 should also receive class 2, remove the first test:

    =IFS(E128<=350,2,E128<=631,4,E128<=1200,8,TRUE,10)
    

    What is wrong with the original formula

    The expression starts with:

    IF(AND(E128>0,E128<350),2,0) * ...
    

    Outside that first range, this returns 0. Because it is multiplied by everything after it, the entire formula must then return zero.

    Additionally, OR returns only TRUE or FALSE; it does not select and return values such as 4, 8, or 10. Nonzero numeric arguments such as 4 are treated as true in that logical test. OR is intended to determine whether any supplied condition is true, while IF supplies the value to return. ^2^ The documented pattern is IF(AND(conditions), value_if_true, value_if_false) or IF(OR(conditions), value_if_true, value_if_false). ^3^

    Your original comparisons also exclude exactly 350, 631, and 1200, because both neighboring tests use strict < and > comparisons. Using <= in the ordered formula assigns each boundary to one class without overlaps or gaps.


    References

    1. IFS function | Microsoft Support
    2. OR function | Microsoft Support
    3. Using IF with AND, OR, and NOT functions in Excel | Microsoft Support
    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.