Google Sheets recipe
How to create a dropdown list in Google Sheets
Select the cells, open Data → Data validation and add a rule that takes its items either from a typed list or from a range. A range is easier to maintain, and SORT with UNIQUE can build that range from the data itself. Once the cells hold the chosen values, COUNTIF and SUMIF work on them like on any text.
Steps
- Put the values in one column, for example B2:B6, under a header such as Status.
- Select the cells that will get the dropdown, here B2:B6.
- Open Data → Data validation and add a rule.
- Give the items as a typed list (Open, Won, Lost) or point the rule to a range such as D2:D4 that holds them.
- To build that range from existing data, use the SORT and UNIQUE formula from the third example in a spare column.
- Count the chosen values with COUNTIF and total another column by status with SUMIF, as in the first two examples.
Examples
The examples use this table, starting in A1:
| Task | Status | Hours |
| Report | Open | 3 |
| Invoice | Won | 5 |
| Audit | Open | 2 |
| Pitch | Lost | 4 |
| Review | Maybe | 6 |
=COUNTIF(B2:B6, "Open")Result: 2
How many rows carry one of the dropdown values. Here two tasks are Open.
Run in a Google Sheet (English US locale) on .
=SUMIF(B2:B6, "Won", C2:C6)Result: 5
Adds the hours of the rows whose status is Won, so the dropdown becomes a filter for totals.
Run in a Google Sheet (English US locale) on .
=SORT(UNIQUE(B2:B6))Result:
| Lost |
| Maybe |
| Open |
| Won |
Builds the list of distinct statuses in alphabetical order. Put it in a spare column and use that range as the source of the dropdown. Note that Maybe shows up too.
Run in a Google Sheet (English US locale) on .
=ARRAYFORMULA(COUNTIF(B2:B6, SORT(UNIQUE(B2:B6))))Result:
| 1 |
| 1 |
| 2 |
| 1 |
One count per distinct status, in the same order as the sorted list. A value that is not in the dropdown list gets its own row here.
Run in a Google Sheet (English US locale) on .
Common errors
- A value outside the list is not removed. Written through the Sheets API into a cell with the rule, Maybe stayed in the cell both when the rule was strict and when it was not. UNIQUE and COUNTIF show such values, so run them from time to time.
- A typed list is stored inside the rule, while a range rule keeps a reference to the cells, so editing the range changes the dropdown. Both were accepted and read back with showCustomUi set to true.
- COUNTIF ignores case, so open and Open are counted together, but a space at the end, as in "Won ", is a different value and counts as 0 against Won.
Compared with Excel
In Excel the list rule lives under Data → Data Validation, with the Allow type set to List. The COUNTIF and SUMIF formulas are the same. SORT and UNIQUE exist only in recent Excel versions.