国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home Topics excel Excel COUNTIF and COUNTIFS with OR logic

Excel COUNTIF and COUNTIFS with OR logic

Apr 07, 2025 am 09:42 AM

This tutorial demonstrates how to use Excel's COUNTIF and COUNTIFS functions to count cells meeting multiple OR conditions (e.g., if a cell contains X, Y, or Z).

While COUNTIF handles single criteria and COUNTIFS uses AND logic, this tutorial provides solutions for OR logic scenarios. It assumes familiarity with the basic syntax and usage of both functions.

Counting Cells with OR Conditions

The simplest case involves counting cells satisfying at least one of several conditions.

Method 1: COUNTIF COUNTIF

This adds the results of individual COUNTIF functions for each criterion. For example, to count cells in column A containing "apples" or "bananas":

=COUNTIF(A:A, "apples") COUNTIF(A:A, "bananas")

Using cell references (e.g., criteria in F1 and G1) improves efficiency and maintainability:

=COUNTIF(A2:A10, F1) COUNTIF(A2:A10, G1)

Excel COUNTIF and COUNTIFS with OR logic

Method 2: COUNTIF with Array Constant

This offers a more compact approach:

SUM(COUNTIF(*range*, {*criterion1*, *criterion2*, *criterion3*, …}))

The criteria are enclosed in an array constant {"apples","bananas","lemons"}. COUNTIF returns multiple counts, which SUM adds.

=SUM(COUNTIF(A2:A10,{"apples","bananas","lemons"}))

Excel COUNTIF and COUNTIFS with OR logic

Using cell references (F1:H1) requires an array formula (Ctrl Shift Enter):

=SUM(COUNTIF(A2:A10,F1:H1))

Excel COUNTIF and COUNTIFS with OR logic

Method 3: SUMPRODUCT

SUMPRODUCT(1\*(*range* ={*criterion1*, *criterion2*, *criterion3*, …})) or SUMPRODUCT((*range*=*criterion1*) (*range*=*criterion2*) …)

This tests each cell against each criterion, summing the resulting TRUE/FALSE array (converted to 1/0).

=SUMPRODUCT(1*(A2:A10={"apples","bananas","lemons"}))

or

=SUMPRODUCT((A2:A10="apples") (A2:A10="bananas") (A2:A10="lemons"))

Using cell references (F1:H1):

=SUMPRODUCT(1*( A2:A10=F1:H1))

Excel COUNTIF and COUNTIFS with OR logic

Note: SUMPRODUCT can be slower than COUNTIF for large datasets.

Counting Cells with OR and AND Logic

This extends the concept to include both OR and AND conditions. For example, counting "apples," "bananas," or "lemons" that are "delivered" (column A and column C):

Method 1: COUNTIFS COUNTIFS

This adds multiple COUNTIFS functions, each checking one OR condition and the AND condition.

=COUNTIFS(A2:A10, "apples", C2:C10, "delivered") COUNTIFS(A2:A10, "bananas", C2:C10, "delivered") COUNTIFS(A2:A10, "lemons", C2:C10, "delivered")

Excel COUNTIF and COUNTIFS with OR logic

Method 2: COUNTIFS with Array Constant

A more concise version using an array constant for OR criteria:

=SUM(COUNTIFS(A2:A10, {"apples","bananas","lemons"}, C2:C10, "delivered"))

With cell references (F1:H1 and F2), an array formula (Ctrl Shift Enter) is needed:

=SUM(COUNTIFS(A2:A10,F1:H1,C2:C10,F2))

Excel COUNTIF and COUNTIFS with OR logic

Wildcards are supported (e.g., "*bananas*"). Additional AND conditions can be added to COUNTIFS.

Counting Cells with Multiple OR Conditions

For multiple sets of OR criteria, COUNTIFS with array constants (limited to two sets) or SUMPRODUCT with ISNUMBER and MATCH (handles more sets) are used.

For two sets, use horizontal and vertical arrays within COUNTIFS:

=SUM(COUNTIFS(A2:A10, {"apples", "bananas", "lemons"}, B2:B10, {"delivered"; "in transit"}))

Excel COUNTIF and COUNTIFS with OR logic

For multiple sets, SUMPRODUCT with MATCH is more versatile:

=SUMPRODUCT(ISNUMBER(MATCH(A2:A10,{"apples","bananas","lemons"},0))*ISNUMBER(MATCH(B2:B10,{"bag","tray"},0))*ISNUMBER(MATCH(C2:C10,{"delivered","in transit"},0)))

Excel COUNTIF and COUNTIFS with OR logic

This tutorial provides various methods for handling OR conditions in Excel's counting functions, catering to different complexity levels and dataset sizes. A sample workbook is available for further practice.

The above is the detailed content of Excel COUNTIF and COUNTIFS with OR logic. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)