Search code examples
regexgoogle-sheetsgoogle-sheets-formulaarray-formulas

How do I match a Column that has a Value with a Column that has a range when ranges have multiple steps


I have two columns. One has a numeric value and another has a range.

I need to match the value from the first column to the range on the second column and return a true or false in a third column.

I'm assuming I'd need to use the IFS function, but not entirely sure how.

The ranges column has the following ranges: 1-15, 15-30, 30-50, 50+

The value column would just have a number.

I've tried messing around with the IFS function:

=IFS((D2<=15, e2="1-15", true, false), (d2<=30, e2="15-30", true, false), (d2<=50, e2="30-50", true, false))

Basically, I want it to be:

Column 1 Column 2 Column 3
1        1-15     TRUE
16       1-15     FALSE
54       30-50    FALSE

Solution

  • It looks to me as though you might as well split the end points of the ranges:

    =and(A2>=1*left(B2,find("-",B2)-1),A2<=1*mid(B2,find("-",B2)+1,len(B2)))
    

    Assuming 1 is in A2,