How to Use the AND Logical Function in Arrays in Google Sheets

Published on

The AND logical function works with arrays in two ways in Google Sheets: it can return a single output or expanded results.

If you want to evaluate all values in an array and return TRUE or FALSE when they meet all conditions, you can apply the AND function with the ARRAYFORMULA.

If you want to use the AND function in an array to test if any conditions apply individually in each row, use AND with the MAP and LAMBDA functions. There is also a popular alternative using the logical * operator.

Let’s look at examples of using the AND function in arrays in Google Sheets.

Using the AND Logical Function in Arrays for a Single Output

The following formula tests whether all the values in the range B2:B12 fall between 50 and 100, returning TRUE or FALSE:

=ArrayFormula(AND(B2:B12>50, B2:B12<100))
Example of using the AND function in a one-dimensional array for a single output

This type of ARRAYFORMULA application is useful when you want to check whether all the test scores fall within the specified limits.

Here is another scenario where we test whether all the values in C2:C7 are greater than 10 and the values in D2:D7 are “Stock”:

=ArrayFormula(AND(C2:C7>10, D2:D7="Stock"))

This helps us verify that we have sufficient quantities in stock.

Example of using the AND function in a 2D array for a single output

I hope these two examples help you understand the use of the AND logical function in arrays to get a single Boolean output.

Using the AND Logical Function in Arrays for Expanded Results

In both of the above examples, the AND function helps us determine whether the conditions are met. If the conditions are not met, we cannot identify the specific rows where they are not satisfied. This is where the following solutions become useful, as they allow us to expand the results for better clarity.

We can use the MAP function to expand the AND function results or use the * operator as an alternative to the AND function to expand the results.

Let’s take the second example above and apply the AND logical function to return expanded results in the arrays.

Using the Multiplication (*) Operator as an Alternative

The following formula in cell E2 will return 0 (FALSE) or 1 (TRUE) in the range E2:E7:

=ArrayFormula((C2:C7>10)*(D2:D7="Stock"))
Using the multiplication (*) operator as an alternative for expanded AND results

This formula works as follows:

  • =ArrayFormula(C2:C7>10) // returns an array of TRUE or FALSE
  • =ArrayFormula(D2:D7="Stock") // returns an array of TRUE or FALSE

In Google Sheets, the Boolean TRUE is equal to 1 and FALSE is equal to 0.

When you multiply these results (two arrays), the output is 1 if both conditions are met (TRUE * TRUE) and 0 if any condition is not met (FALSE * FALSE, FALSE * TRUE, TRUE * FALSE).

This is the logic behind using the alternative AND operator in an array for expanded results.

Using the MAP Lambda Functon

Instead of the above formula, you can also use the following MAP LAMBDA function in cell E2:

=MAP(C2:C7, D2:D7, LAMBDA(value1, value2, AND(value1>10, value2="Stock")))

This may look complex but is simple if you follow three steps:

  1. Code the formula for the first row: =AND(C2>10, D2="Stock") // This will test if both conditions are met.
  2. Convert that to a LAMBDA function: =LAMBDA(value1, value2, AND(value1>10, value2="Stock")) // This LAMBDA function uses value1 and value2 to represent C2 and D2, respectively.
  3. Map each value through the arrays using that LAMBDA function to get expanded results.

We specify the arrays C2:C10 and D2:D10 in MAP. It maps each value in the arrays (value1 in C2:C10 and value2 in D2:D10) to a new value by applying the LAMBDA function to each value.

Resources

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Guide Prashanth KV brings a wealth of experience in Google Sheets and Excel, cultivated through years of work with multinational corporations in Mumbai and Dubai. As a recognized Google Product Expert in Docs Editors, Prashanth shares his expertise through insightful blogging since 2012. Explore his blog for practical tips and guidance on maximizing your spreadsheet skills.

Compare Two Tables for Differences in Excel

To compare two tables with similar data for differences, you can use the XLOOKUP...

Calculate Weighted Average in Pivot Table in Google Sheets

You can calculate a weighted average in a Pivot Table using a custom formula...

Summarize Data and Keep the Last Record in Google Sheets

In Google Sheets, we can summarize data (like sum, average, min, max, count) using...

How to Retrieve the Last Record in Each Group in Excel

As part of data analysis, you may need to retrieve the last record from...

More like this

Calculate Weighted Average in Pivot Table in Google Sheets

You can calculate a weighted average in a Pivot Table using a custom formula...

Summarize Data and Keep the Last Record in Google Sheets

In Google Sheets, we can summarize data (like sum, average, min, max, count) using...

Filter Data with Multi-Select Drop-Downs in Google Sheets

If you've started using multi-select drop-downs in Google Sheets, you may encounter challenges when...

7 COMMENTS

  1. So I have ArrayFormula checking Column C Price to see what range it falls in. Then it assigns the number based on that range it puts it in Column M. It works perfectly as a formula, but when I make it an array, it just posts all Zeros. So not seeing any in the range, but they all are. I love your site and have search it but couldn’t figure it out. Thank you.

    Note:- Formula removed by admin due to improper formatting.

    • Hi, Tim Murray,

      Sorry that my editor sometimes automatically removes the greater than or equal to operators. Anyhow, I have got your mail with the correct formula. I will check it later and reply back.

    • Hi, Tim Murray,

      This may help.

      ={"Price Range ID";ArrayFormula(if(C2:C>0,IF(C2:C<150001,1,IF(C2:C<250001, 2, IF(C2:C<350001,3, IF(C2:C<450001,4, IF(C2:C<=550001,5, IF(C2:C<=650001,6, IF(C2:C<750001,7, IF(C2:C<900001,8, IF( C2:C<1200001,9,0))))))))),))}

      The AND operator in your formula won't support the array formula.

      Actually, the said logical operator is not required in your formula.

  2. Hi,
    Your info is a true inspiration. can you help me, please? My formula is;

    =IFS(N2:N=20000000;N2:N=100000000;N2:N=300000000;
    N2:N=500000000;N2:N=700000000;N2:N=1000000000;
    3250000+(0,5%*N2:N))

    How to use it in the array formula? Thanks.

    • Hi, Rahmat Jaenudin,

      See if this formula helps?

      =ArrayFormula(IF((N2:N=20000000)+(N2:N=100000000)+(N2:N=300000000)+(N2:N=500000000)+(N2:N=700000000)+(N2:N=1000000000)>=1;3250000+(0,5%*N2:N);))

  3. I’ve shortened it to this:

    =Arrayformula(if(B4:B76*B3:B75>0,B4:B76-B3:B75,""))

    I’ve needed it to subtract earlier time from later time to get the duration of an activity performed during that time. Basically B4-B3, B5-B4 etc. – but only if both of the cells in subtraction are not empty, in order to keep result column clean. It worked.

    Thanks for the guidance and inspiration and – what do you think? 🙂

    • Hi, Dodo Phe,

      I think your formula may not work as desired.

      Check the output properly. You may need a more complicated formula.

      =Query(ArrayFormula(IFERROR(IF(ISEVEN(if(len(B4:B),row(B4:B),))=true,B4:B,)-IF(ISODD(if(len(B3:B),row(B3:B),))=true,B3:B,))),"Select * where Col1>0")

      Best,

      Prashanth KV

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.