Sub topic 8
Driving criteria from cells
This chapter assumes you can enter and copy formulas, know the difference between relative and absolute references, and have the sample sales data from the earlier chapters (Date, Region, Product, Amount, Notes in A1:E100).
Why move criteria out of formulas
A criterion typed inside a formula, such as "West", is hard to change. You have to edit every formula that uses it. If you put the value in a cell and point the formula at that cell, you change one cell and all the results update.
For example, put West in G1. This formula then totals West sales:
=SUMIFS(D2:D100, B2:B100, G1)Type East in G1 and the total changes. The formula does not need editing.
Joining an operator to a cell value
A cell reference alone means "equals this value". To use an operator such as >=, write the operator as quoted text and join it to the cell with &. Suppose G1 holds the minimum amount, for example 500:
=SUMIFS(D2:D100, B2:B100, "West", D2:D100, ">=" & G1)Excel builds the text ">=500" and uses it as the criterion. The operator goes in quotes. The cell reference does not.
Common mistakes
- Writing
">=G1"puts G1 inside the quotes. Excel then looks for the literal text "G1" and finds no matches, so the result is 0. - Leaving the cell blank. A reference to an empty cell is treated as 0 in the criterion, so it matches cells equal to 0, not "any value". Check that the input cell is filled in.
- Typing extra spaces in the input cell.
Westwith a trailing space does not matchWest.
Using several input cells
You can give each condition its own input cell. Put the region in G1, the product in G2, and the minimum amount in G3:
=SUMIFS(D2:D100, B2:B100, G1, C2:C100, G2, D2:D100, ">=" & G3)Now G1:G3 act as a small control panel. Changing any one of them recalculates the result. This is the base for the summary grids covered later, where the same formula is copied across many cells.
Cell references and dates
Dates work the same way. If G4 holds a start date, join the operator to it:
=SUMIFS(D2:D100, A2:A100, ">=" & G4)The date in G4 must be a real date, not text that only looks like one. A real date is right-aligned by default.
Exercise
Cell H1 holds the number 300. Write a COUNTIFS formula that counts rows in D2:D100 with an Amount greater than the value in H1. Why would ">H1" not work?
Show answer
Use =COUNTIFS(D2:D100, ">" & H1). The text ">H1" has H1 inside the quotes, so Excel compares each Amount to the literal text "H1" instead of the number 300, and nothing matches.