How to Sum Values Using Multiple Name and Subject Criteria
Question details
Summarize cross-tabulated data based on specific name and subject criteria by avoiding merged cells and unpivoting the dataset.

- Product
- Spreadsheet
- Device & OS
- not provided
- Scenario
- Calculating the total sum of specific values when dealing with two variables (name and subject) situated across a two-dimensional matrix or cross-tabulated format.
- Observed behavior
- Users encounter difficulties extracting multi-criteria summaries from cross-tabulated grids, especially when raw data contains merged cells that disrupt array formulas.
Ensure your raw source data is completely normalized and contains no merged cells, as merged cells prevent array formulas and pivot functions from reading rows and columns correctly.
Unpivot Matrix Data and Summarize with PIVOTBY
Use a combination of a custom LAMBDA function and dynamic arrays to flatten your cross-tabulated data and calculate sums across multiple criteria seamlessly.
If your data is currently arranged as a cross-tabulation (e.g., subjects in rows and names in columns), it needs to be unpivoted into a flat format before applying standard criteria-based summaries. This can be accomplished using a custom LAMBDA function named 'UnPivotM' alongside the 'LET' and 'PIVOTBY' functions.
Go to Formulas > Name Manager. Create a new name called 'UnPivotM' and assign a LAMBDA formula capable of unpivoting a 2D matrix into three columns (Row Labels, Column Labels, and Values).
Select the cell where you want your multi-criteria summary to appear. Enter the following formula: =LET(flattened,UnPivotM(A4:A6,B2:I2,B4:I6),row_label,TAKE(flattened,,1),col_label,CHOOSECOLS(flattened,2),val,TAKE(flattened,,-1),PIVOTBY(row_label,col_label,val,SUM))
Modify 'A4:A6' to match your row headers (e.g., names), 'B2:I2' for your column headers (e.g., subjects), and 'B4:I6' for the actual cross-tabulated values you wish to aggregate.

Format Raw Data for Traditional Multi-Criteria Summaries
Optimize your source data by unmerging cells to allow standard aggregation formulas like SUMIFS or built-in PivotTables to work properly.
Easily Sum Values by Multiple Criteria in WPS Spreadsheet
WPS Spreadsheet provides powerful dynamic array functions and intuitive data analysis tools to seamlessly summarize complex cross-tabulated data.
- 1. Open your dataset in WPS Spreadsheet: Launch WPS Office and open the workbook containing your cross-tabulated names and subjects.
- 2. Unmerge cells quickly: Highlight your data, navigate to the Home tab, and use the 'Unmerge' tool to ensure your data matrix is clean and formula-ready.
- 3. Apply advanced formulas or PivotTables: Either enter your dynamic array formulas to flatten and sum the data, or go to Insert > PivotTable to aggregate your data by Name and Subject criteria effortlessly.

Frequently Asked Questions
Why do merged cells cause errors in SUM and Pivot formulas?
Merged cells disrupt the strict row and column indexing required by array formulas and PivotTables. When cells are merged, only the top-left cell retains the data, making the subsequent referenced cells appear blank to the aggregation engine.
What is the PIVOTBY function?
PIVOTBY is an advanced dynamic array function that allows you to group, sort, and aggregate data directly within a cell using a formula. It essentially creates a lightweight pivot table using row labels, column labels, and a specified calculation like SUM.
What does it mean to unpivot a matrix?
Unpivoting means taking a two-dimensional grid of data (where variables exist in both column and row headers) and flattening it into a tabular format, usually consisting of three columns: Row Attribute, Column Attribute, and Value. This is the optimal structure for data analysis.
Can I use standard SUMIFS instead of PIVOTBY for multiple criteria?
Yes, but SUMIFS requires your data to already be in a flattened, tabular format. If your source data is cross-tabulated in a matrix, you must first unpivot the data before SUMIFS can properly evaluate the multiple criteria.




