Home » excel » How to include OR in Array formula where ONLY SOME criteria need to be TRUE – Excel Part 2

# How to include OR in Array formula where ONLY SOME criteria need to be TRUE – Excel Part 2

Posted by: admin May 14, 2020 Leave a comment

Questions:

This is an extension of this question, which was answered by XOR LX.

In the original question, I wanted to count the number of rows in a matrix that included values that fulfilled at least one column-specific criteria. The columns referenced were sequential (e.g., A1:D4), but the situation requires indexing columns that are not sequential.

Take the data matrix:

``````A B C D E F G H
4 2 2 2 1 4 2 4
5 2 1 3 4   1
3 2 1     4 5 1
1 2 3 5 3 2 2 2
2 2 2 2 2 2 2 2
``````

With the column-specific criteria:

• Column A criteria: >2
• Column B criteria: >2
• Column C criteria: <2
• Column D criteria: >4
• Column E criteria: >2
• Column F criteria: >3
• Column G criteria: >2
• Column H criteria: >3

In order to count the number of rows that have values for all columns, as well as meet at least column-specific criterion, we could use XOR LX’s code:

``````=SUM(N(MMULT(IF(MMULT(N(A1:H5=""),TRANSPOSE(COLUMN(A1:H5)^0))=0,COUNTIF(OFFSET(A1,ROW(A1:H5)-MIN(ROW(A1:H5)),COLUMN(A1:H5)-MIN(COLUMN(A1:H5))),{">2",">2","<2",">4",">2",">3",">2",">3"}),0),TRANSPOSE(COLUMN(A1:H5)^0))>0))
``````

…which might have some problems with handling blanks, so the alternative:

``````=ROWS(A1:D4)-COUNTIFS(A1:A5,"<=2",B1:B5,"<=2",C1:C5,">=2",D1:D5,"<=4",E1:E5,">=2",F1:F5,">=3",G1:G5,">=2",H1:H5,">=3")-COUNT(1/N(MMULT(N(A1:H5=""),TRANSPOSE(COLUMN(A1:H5)^0))>0))
``````

…which as far as I have tested seems to handle blanks regardless of their frequency or location.

But what if only rows with data for certain should be counted, ignoring the other columns. Furthermore, what if only certain columns should be evaluated for their criteria?

Let’s take the example above. Our goal is to count the number of rows with i) full data in certain columns and ii) entries in certain columns that meet at least one column-specific criterion.

The relevant columns that should have full data are A:C and F:H. The columns that should be evaluated for their criteria are A:C only. The solution is 2 since:

• There are 5 rows in total, but only rows 1, 3, 4, and 5 qualify as they have full data in columns A:C and F:H. Row 2 has missing data in column A and also G, either of which should disqualify its inclusion. Notice that even though row 3 has missing data in columns D and E, it is still included because these columns are not important.
• Rows 1 and 3 meet the specified criteria, since i) they have full data in columns A:C and F:H, and ii) at least one entry meets one of the criteria for columns A, B, and C; specifically, the value in row 1, column A (4 > 2), and row 3, column A (3 > 2) and column C (1 < 2). Notice that this is still only counted as one row meeting the criteria, even though the criteria for 2 columns is met.

Your thoughts would be most welcome. Please also show some love to XOR LX in the original post – I am sure you will find his solution helpful.

How to&Answers:

@PyjamaNinja has encouraged me to try and develop my ‘lemma’ to their earlier question.

The method is:

``````A Count rows with entries in all specified columns (A-C and F-H)

B Count rows with entries in all specified columns that do _not_ meet any of the criteria in the columns being evaluated (A-C).

Subtract B from A.

=COUNTIFS(A1:A5,"<>",B1:B5,"<>",C1:C5,"<>",F1:F5,"<>",G1:G5,"<>",H1:H5,"<>")-COUNTIFS(A1:A5,"<=2",B1:B5,"<=2",C1:C5,">=2",F1:F5,"<>",G1:G5,"<>",H1:H5,"<>")
``````

With many thanks to @XOR LX. 