Sub topic 7
Using Cell Values in Criteria with the `&` Operator
Assume you know how to enter formulas, use ranges such as A2:A100, and use basic functions such as SUM and COUNT. This chapter shows how to make a comparison criterion depend on a cell value.
A criterion is the rule that determines which rows a function includes. For example, ">100" means “greater than 100.” When the value comes from another cell, join the operator and the cell reference with the ampersand (&) operator.
Build a criterion from a cell
Suppose column D contains Units and cell H1 contains a minimum value. This formula sums Revenue in column E only when Units is greater than the value in H1:
=SUMIFS(E2:E100, D2:D100, ">"&H1)If H1 contains 10, Google Sheets evaluates the criterion as ">10". If you change H1 to 25, the same formula now uses ">25".
The & operator joins text. In this example, it joins the text ">" with the value in H1.
Use criteria with multiple conditions
Each condition in SUMIFS is supplied as a range and a criterion. For example, this formula sums Revenue for the West region when Units is greater than the value in H1:
=SUMIFS(E2:E100, A2:A100, "West", D2:D100, ">"&H1)The conditions combine with AND logic. A row must have West in column A and a Units value greater than H1 in column D.
| Region | Units | Revenue |
|---|---|---|
| West | 12 | 500 |
| West | 8 | 300 |
| East | 20 | 700 |
With H1 set to 10, only the first row qualifies.
Use other comparison operators
You can build criteria with >, <, >=, <=, =, and <>.
=COUNTIFS(D2:D100, "<="&H1)
=COUNTIFS(D2:D100, "<>"&H1)
=AVERAGEIFS(E2:E100, D2:D100, ">="&H1)The first formula counts values less than or equal to H1. The second counts values that are not equal to H1. The third averages Revenue for rows whose Units value is at least H1.
You can also use a cell containing text:
=SUMIFS(E2:E100, A2:A100, G2)If G2 contains West, the formula sums Revenue for West rows. No & is needed because the cell supplies the complete criterion rather than part of one.
Common errors
Check these points when a formula returns an unexpected result:
- Use matching range sizes, such as
E2:E100andD2:D100. - Store numeric thresholds as numbers, not text that includes the operator.
- Use
&when combining an operator with a cell value. - Confirm that dates are real date values if you build date criteria.
- Remember that
">"&H1means greater than H1, whileH1alone means equal to H1.
Exercise
H1 contains 10. Write a formula that counts rows where Region is West and Units is at least H1.
Show answer
=COUNTIFS(A2:A100, "West", D2:D100, ">="&H1)