Forum Discussion

Arnaud1995's avatar
Arnaud1995
Copper Contributor
Sep 08, 2023
Solved

Simpler logical test syntax for criteria against multiple values

I'm desperately looking for a leaner formula for =IF(A1=any of {value A,value B,value C, etc},TRUE,FALSE) with resorting to the classic use OR =IF(OR(A1=value A,A1=value B,A1=value C,etc),TRUE,FALSE) which becomes super long when the list of values grows.

 

Note that I do not want an array formula that would return multiple values.

 

In Excel, i can easily have these functions =SUMIF(range;criteria) or =COUNTIF(range;criteria) that have a simple and legible syntax when testing against instances of a single particular value (criteria). But if i want to test against instances of a list of multiple values instead, eg cell A1 is any of {"Apples","Oranges","Bananas"} that would return a single TRUE value if there is at least one match. There are many ways to do this with OR / MATCH / INDEX combinations but with many values the formula becomes super long in not so legible. I'm looking for a straight forward formula that would allow for a list as criteria in a short and simpler syntax. For example

  • =SUMIF(range,"apples" or "oranges")
  • =SUMIF(range,any value in cells of the range C2:C8)
  • =COUNTIF(A2:A5;>5)
  • a boolean formula =IS_IN_LIST(single_value;criteria) that would return TRUE or FALSE depending on whether value belongs to to the criteria range/list, eg =IS_IN_LIST(A1;"potatoes" or "oranges").

(note: the syntax is approximate, i hope you get the gist of it).


Any suggestion folks?

2 Replies

  • Arnaud1995 

    =SUM(SUMIF(criteria_range, {"apples", "oranges"}, sum_range))

    =SUM(SUMIF(criteria_range, C2:C8, sum_range))

    • Arnaud1995's avatar
      Arnaud1995
      Copper Contributor

      HansVogelaar 

      Thank you very much Hans. Sorry it takes a while. I will revert after exploring what your sleek suggestion covers and what still need to be sleekified!

Resources