Create a Dynamic Category Count
Generate a sorted distinct-category list from changing source data, count each returned category, and reconcile the dynamic summary directly to the full number of source records.
| Dynamic Summary Count, Formula Review | |||||||||
| SORT and UNIQUE create the category spill; COUNTIF returns one aligned count per category. | |||||||||
| Local source list | Dynamic category summary | Formula roles | |||||||
| Record | Category | Category | Count | Step | Formula syntax | ||||
| Record 1 | Red | Blue | 2 | Distinct values | =UNIQUE(B12:B18) | ||||
| Record 2 | Blue | Gold | 1 | Alphabetical order | =SORT(UNIQUE(B12:B18)) | ||||
| Record 3 | Red | Green | 1 | Aligned counts | =IF(E12="","",COUNTIF($B$12:$B$18,E12)) | ||||
| Record 4 | Green | Red | 3 | ||||||
| Record 5 | Blue | (unresolved) | |||||||
| Record 6 | Red | (unresolved) | |||||||
| Record 7 | Gold | (unresolved) | |||||||
| Spill behavior | |||||||||
| The sorted category list spills from E12. Count formulas are reserved beside the full source capacity and stay blank until a category appears. | |||||||||
Overview
Turn one repeating category column into an alphabetical frequency summary. SORT and UNIQUE return a spilled list of distinct categories; adjacent COUNTIF formulas return one count per visible category. The summary expands when a new category appears in the bounded source.
When to use it
Use it for lightweight counts by status, team, type, owner, or other category when the list of possible values can change. It suits small reporting tables and data-quality reviews where newly introduced labels should become visible automatically.
When not to use it
Use a PivotTable when users need interactive filters, grouping, or a refresh-managed report. Use COUNTIFS when each category also needs other conditions. Use an all-in-one LET and HSTACK formula when Microsoft 365 is required and both columns must spill from one anchor.
Problem
A manually maintained category list omits new values and retains obsolete ones. A distinct list alone does not show frequency, while copied counts without reserved capacity can stop before the source reaches its maximum number of categories. The list and counts must stay aligned as the source changes.
Source data
The synthetic source in Combined Example!A12:B23 contains 12 record labels and categories. Its frequency distribution is:
Category | Source occurrences |
|---|---|
Blue | 3 |
Gold | 2 |
Green | 2 |
Purple | 1 |
Red | 4 |
Categories are text. Repeated values are expected; hidden leading or trailing spaces create separate categories. The bounded range includes no header. A blank-category reporting policy should be defined before adapting the formula.
Calculations
- Extract each distinct category once with UNIQUE.
- Sort the returned values alphabetically.
- Spill the list from one anchor cell.
- Count each visible category against the locked source range.
- Return blanks beside unused reserved rows.
- Reconcile all displayed counts to the source-record count.
Outputs
The spill in Combined Example!E12 returns Blue, Gold, Green, Purple, and Red. Adjacent counts are 3, 2, 2, 1, and 4. Five unique categories are displayed, and their counts total 12, matching the 12 source records.
Formula map
Sorted category spill
=SORT(UNIQUE(B12:B23))
Enter this once in E12 and leave the cells below clear.
Aligned count
=IF(E12="","",COUNTIF($B$12:$B$23,E12))
Copy this formula through the reserved count rows. The source is absolute while the category criterion moves by row.
Model checks
The workbook confirms that the sum of category counts equals the number of source records and that the sample produces five unique categories. Both tests return OK when the spill and copied formulas are aligned.
Edge cases
- A new category expands the spill only when the destination cells are clear.
- Occupied spill cells produce
#SPILL!in Excel. - Duplicate categories increase one count rather than adding summary rows.
- Hidden spaces or inconsistent spelling create visually similar but distinct groups.
- Blank categories require an explicit include, exclude, or relabel decision.
- The copied COUNTIF area must reserve enough rows for the maximum distinct count.
Common errors
- Maintaining a manual list: new categories go missing. Generate the list from the source with UNIQUE.
- Blocking the spill area: the category formula cannot expand. Keep the reserved output range empty.
- Moving the COUNTIF source: copied ranges stop referring to the same data. Lock the source and leave only the criterion relative.
Example
The 12 source rows contain Red four times, Blue three, Gold twice, Green twice, and Purple once. UNIQUE reduces those values to five labels, SORT orders them, and COUNTIF returns 3 + 2 + 2 + 1 + 4 = 12. The sum independently reconciles to the source record count.
Example workbook
Replace the cream categories in Combined Example!B12:B23. The category spill begins at E12; reserved count formulas run alongside it, and summary measures and checks appear in J12:J14. Formula Review isolates the same logic with seven local rows.
Key takeaway
Generate category labels from the live source, keep the spill area clear, and count each returned value against one locked range so the summary remains aligned.