How to Count Invoices by Contract in Excel Without a Helper Column
Question details
The user needs to dynamically count the number of nonblank invoices associated with each contract without relying on helper columns or manually refreshing a pivot table.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Managing a large master dataset (e.g., 9,400 contracts) that feeds charts, requiring automatic and dynamic updates when new invoices are added or removed.
- Observed behavior
- The goal is to automatically output a list of unique contracts alongside their respective nonblank invoice counts directly within the spreadsheet, avoiding manual intervention.
Ensure your dataset is formatted as an official Data Table (Ctrl+T) so that formulas automatically expand to include new rows, and verify your spreadsheet software supports dynamic arrays if using advanced functions.
Use a Dynamic Array Formula (LET, UNIQUE, and HSTACK)
This method utilizes modern dynamic array functions to generate both the unique list of contracts and their respective invoice counts in a single step.
By combining LET, UNIQUE, FILTER, and HSTACK, you can create a single formula that reads the master data, extracts unique contracts, and tallies the nonblank invoices for each. Because it uses structured table references, the results scale dynamically as data changes.
Confirm the name of your table (e.g., Table1) and the specific columns for contracts (Table1[Contract]) and invoices (Table1[Invoice]).
Click on the top-left cell where you want the dynamic list of contracts and counts to begin.
Type the formula: =LET(contracts,FILTER(Table1[Contract],Table1[Contract]<>""),uniqueContracts,UNIQUE(contracts),HSTACK(uniqueContracts,COUNTIFS(Table1[Contract],uniqueContracts,Table1[Invoice],"<>")))
Press Enter. The formula will automatically spill the unique contract names in the first column and their nonblank invoice counts in the adjacent column.

Use Traditional COUNTIFS with an Explicit Contract List
A highly compatible method for older versions of spreadsheet software that do not support dynamic array functions.
Effortlessly Count and Manage Complex Data in WPS Spreadsheets
WPS Office provides robust formula support, fully handling complex master datasets and advanced COUNTIFS functions without slowing down your system.
- 1. Import your dataset: Open your large master dataset securely in WPS Spreadsheets.
- 2. Format as a Data Table: Select your dataset and press Ctrl+T to convert it into a dynamic table.
- 3. Apply advanced functions: Input your COUNTIFS or dynamic formulas to instantly generate accurate invoice counts.
- 4. Connect to charts: Highlight your dynamically generated data and insert a chart from the Insert tab to create a real-time dashboard.

Frequently Asked Questions
Why is my dynamic array formula returning a #SPILL! error?
A #SPILL! error occurs when the formula's output range is blocked by existing data or text. Clear all the cells below and to the right of your formula cell to allow the array results to expand and populate properly.
Can I use a Pivot Table instead of formulas for counting invoices?
Yes, Pivot Tables are excellent for summarizing data. You can place 'Contract' in the Rows area and 'Invoice' in the Values area (set to Count). However, unlike dynamic formulas, you must manually refresh the Pivot Table (Right-click > Refresh) whenever your source data changes.
How do I count only specific types of invoices using COUNTIFS?
You can add additional criteria ranges and conditions to your COUNTIFS function. For example, =COUNTIFS(Table1[Contract], "Contract A", Table1[Invoice], "<>", Table1[Status], "Paid") will only count nonblank invoices that are marked specifically as paid.
Are functions like LET and HSTACK supported in older versions of Excel?
No, dynamic array functions like LET, HSTACK, and UNIQUE require modern versions of spreadsheet software, such as Microsoft 365, Excel 2021, or the latest editions of WPS Office. For older versions, you must rely on traditional COUNTIFS coupled with a manually generated unique list.




