Knowledge base / Excel
COUNTIFS in Excel: several conditions on the same row
Six synthetic orders show what the count represents and why date boundaries and matching row positions must be explicit.

I use COUNTIFS when a match requires several conditions simultaneously. For example: the product is a laptop, the country is Poland and the order value exceeds a threshold. In a table, I check all conditions on the same row before increasing the count. Adding a separate laptop count, Polish-order count and high-value count would answer a different question. The relationship between the fields is part of the calculation.
Syntax: a range and its criterion form a pair
=COUNTIFS(criteria_range1,criteria1,[criteria_range2,criteria2],...)
The first pair is required and later pairs are optional, up to 127 pairs. Microsoft’s documentation requires every range to have the same number of rows and columns. They need not be adjacent. For a table, I also make sure they cover corresponding record rows. Matching size alone does not rescue a reference shifted by one row. Syntactic validity and a meaningful relationship between records are separate requirements.
The documented versions include Microsoft 365, Excel for the web, Excel 2024, 2021, 2019 and 2016. Here I use English names and commas; the Polish examples use LICZ.WARUNKI and semicolons. Separators depend on regional configuration. I enclose comparison operators in quotes and join an operator to a threshold cell with &. The operator is text, while the reference supplies a value when the criterion is constructed.
A small order table
These are synthetic data in A1:E7, with headers in row one. D contains numbers and E contains real Excel dates and times, rather than date-looking text. The displayed format is for readability; entering the dates must follow the workbook’s configuration. Rows without a time have a time of 00:00. Establishing these types is necessary before applying numerical date comparisons to the column.
| Row | A: ID | B: Product | C: Country | D: Value | E: Date |
|---|---|---|---|---|---|
| 2 | O1 | Laptop | Poland | 120 | 2026-11-01 |
| 3 | O2 | Phone | Poland | 80 | 2026-11-10 |
| 4 | O3 | Laptop | Germany | 150 | 2026-11-30 18:00 |
| 5 | O4 | Laptop | Poland | 100 | 2026-12-01 |
| 6 | O5 | Phone | Poland | 120 | 2026-11-30 12:00 |
| 7 | O6 | Laptop | Poland | 150 | 2026-11-15 |
The row-number column is explanatory; do not insert it before A. Each row represents one order with one product. This simplifies the exercise rather than making an assumption about every sales system. If your source has several lines per order, you must establish the unit before calling the result an order count. The language versions translate the labels while preserving the structure, amounts and timestamps.
Two conditions, then three
=COUNTIFS(B2:B7,"Laptop",C2:C7,"Poland")
The result is 3, covering O1, O4 and O6. O3 is excluded by its country even though its product is a laptop. Add a value condition:
=COUNTIFS(B2:B7,"Laptop",C2:C7,"Poland",D2:D7,">100")
The result becomes 2, for O1 and O6. O4 equals 100 and therefore fails greater than 100. I am not adding the amounts 120 and 150. I am counting two orders satisfying the complete set of criteria. If one source row represented an order line, I would describe the output as a line count or first prepare data at order level. The formula cannot establish the unit by itself.
Two boundaries on the same column
The same range can be supplied more than once to define an interval:
=COUNTIFS(D2:D7,">=100",D2:D7,"<=120")
The result is 3: O1, O4 and O5. Both 100 and 120 are included because the two boundaries are inclusive. O2 lies below the interval, while O3 and O6 lie above it. Microsoft’s examples apply two criteria to one range; this still means satisfying both at once. Repeating a range does not change the logic into an alternative between its criteria.
For a numeric threshold in F2, I write ">"&F2. I do not write ">F2" and expect the cell’s contents to be inserted. When copying, I can fix the threshold as $F$2 and the range as $D$2:$D$7. Keeping a reference fixed is a separate choice from changing greater than to greater than or equal to. I make both choices explicitly so a later copy does not quietly change the question.

November including times on its final day
For a monthly interval, I use an inclusive start and an exclusive start of the following month:
=COUNTIFS(E2:E7,">="&DATE(2026,11,1),E2:E7,"<"&DATE(2026,12,1))
The result is 5, covering every displayed order except O4 on December 1. O3 at 18:00 on November 30 and O5 at 12:00 that day remain inside the interval. DATE constructs a date value, while date and time functions use numerical representations. This comparison therefore requires real date values in E. Changing the display format of text is not the same as supplying those values.
The boundary "<="&DATE(2026,11,30) ends the comparison at the start of November 30, at midnight. It would exclude later times that day. I do not try to repair that by guessing the month’s final second. Using the next month as an excluded end gives a simpler interval description. Constructing criteria with DATE also avoids depending on the interpretation of a date string embedded inside quotation marks, while retaining an explicit year, month and day.
Zero and an error are different situations
For product Tablet and country Poland, this table gives 0. No row satisfies both conditions. A lack of matches is not a reason to describe the function as returning #N/A. When I see zero, I first check names, spaces, types and ranges. Zero can be the correct answer to a poorly specified question, so a successful calculation does not finish the review. The criterion must still mean what the report’s recipient expects.
A range with a different row or column count violates the requirements and can produce #VALUE!. Equally sized ranges shifted by a row create another problem: fields from different records may be compared without an obvious error. Microsoft also documents errors involving closed workbooks. I therefore do not explain every surprising output as a lack of matches. Data alignment, function requirements and the reference environment need separate attention.
An empty criterion and the limits of the function
Microsoft states that when a criterion references an empty cell, the function treats that cell as zero. I do not use an empty settings field as an implicit instruction to skip a condition. The report needs an explicit design for what should happen when that field is left empty. That decision belongs in the definition, rather than being inferred from how the input cell happens to look on the worksheet.
COUNTIFS does not automatically count unique countries. A condition on the value column counts matching orders even when several belong to the same country. The function also does not turn its conditions into OR alternatives. If I need another logic or a sum of amounts, I first describe the new output. For one criterion, see COUNTIF; for content alone, see COUNTA.
An exercise: change one boundary
In the formula for Laptop, Poland and a value greater than 100, replace ">100" with ">=100". O4 should now be included, raising the result from two to three. Then add the November conditions. O4 is excluded again because it belongs to December. At each step, describe which row enters or leaves and why. That account is a better check of understanding than merely looking at the final number and deciding that it seems plausible.
Key takeaways
Does COUNTIFS use AND or OR?
Within one call, all supplied criteria must be satisfied by the corresponding cells. In a table, this usually means an AND condition on the same row.
What is returned when nothing matches?
Zero. A lack of matches does not itself produce #N/A. Still check whether the criteria and data types express your question.
How do I include times on the last day of a month?
Use an inclusive month start and an exclusive start of the next month. Times on the last day are then retained instead of being cut off at its midnight.
AI was used in an automated way while working on this article. If you want to learn how to do it too, check out this project.
