How to Count Excel Cells Using Two Header Rows and a Value
Question details
The user needs to count specific data values in an Excel range based on matching criteria across two separate header rows without triggering a COUNTIFS dimension error.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Counting occurrences of a specific value in a data grid where the corresponding columns must match specific conditions in two different header rows simultaneously.
- Observed behavior
- Using the COUNTIFS function returns a dimension mismatch (#VALUE!) error because the header row criteria ranges and the multi-row data ranges have different sizes. The objective is to evaluate all conditions across the entire array correctly.
Ensure your data ranges and header rows are properly aligned and contain no merged cells, as mismatched array columns will cause the SUMPRODUCT function to return an error.
Use the SUMPRODUCT Function to Count Across Arrays
Use SUMPRODUCT to evaluate multiple arrays with different dimensions, effectively bypassing the limitations of the COUNTIFS function.
The COUNTIFS function requires all criteria ranges to be the exact same size as the count range. Because a data grid spans multiple rows while a header spans only one, COUNTIFS throws a dimension error. SUMPRODUCT resolves this by multiplying boolean arrays across the defined ranges.
Click on the cell where you want the final count result to be displayed.
Type the formula =SUMPRODUCT(($J$3:$Q$6="G")*($J$1:$Q$1="En")*($J$2:$Q$2="E")) into the formula bar. Replace the cell ranges and criteria values inside the quotes with those corresponding to your actual dataset.
Press the Enter key. The function will multiply the array conditions and return the total count of cells that successfully meet all three requirements.

Effortlessly Calculate Multi-Condition Data with WPS Spreadsheet
WPS Spreadsheet fully supports advanced array formulas like SUMPRODUCT, allowing you to seamlessly process multi-dimensional data and complex header conditions without errors.
- 1. Open your workbook: Launch WPS Spreadsheet and open your document containing the multi-header dataset.
- 2. Input the array formula: Select your target cell and type your SUMPRODUCT formula to correlate your data values with the header conditions.
- 3. Get immediate results: Hit Enter to instantly calculate the exact count matching your specified multi-row parameters.

Frequently Asked Questions
Why do I get a #VALUE! error when using COUNTIFS for this task?
The COUNTIFS function strictly requires all criteria ranges and the count range to have the exact same number of rows and columns. When you compare a multi-row data grid to a single-row header, the dimensions mismatch and Excel returns a #VALUE! error.
Can I add a third header row condition to my SUMPRODUCT formula?
Yes. You can simply add another multiplication array to the formula, such as *($J$1:$Q$1="Condition3"). Ensure the column width of this new header range perfectly matches the other ranges in your formula.
Does this SUMPRODUCT method work with both text and numbers?
Yes, SUMPRODUCT can evaluate text strings, numerical values, and dates. Just make sure to enclose text criteria in double quotes (e.g., "TargetText") within your formula, while numbers can be typed directly.




