Sub topic 15
Checking results with SUMIFS and QUERY
A pivot table gives you a number, but it does not tell you whether the number is right. This chapter shows how to rebuild a pivot result with SUMIFS and QUERY, so you can confirm it or find out why it is off.
This chapter assumes you can build a pivot table with Rows, Values and Filters, and that you can write simple formulas. It uses the Sales sheet from earlier chapters. Row 1 holds headers. Column A is Date, column B is Region, column C is Product, column D is Units, and column E is Revenue.
Why cross-check a pivot table
A pivot table summarizes the source range you gave it, using the settings in the editor. Several things can make its numbers differ from what you expect:
- The source range is stale and misses new rows.
- A filter in the pivot table hides some records.
- Revenue values stored as text are counted instead of summed.
- Summarize by is set to COUNTA when you wanted SUM.
A second calculation that does not depend on the pivot table's settings catches these problems. If both methods agree, you can trust the figure. If they disagree, the difference points you to the cause.
Checking one number with SUMIFS
SUMIFS adds the values in one column for rows that meet one or more conditions. Its arguments are the range to sum, followed by pairs of a criteria range and a criterion.
To reproduce the West revenue total, use this formula:
=SUMIFS(Sales!E:E, Sales!B:B, "West")Place it next to the pivot table, then compare it with the pivot cell. You can make the comparison explicit with a difference cell:
=SUMIFS(Sales!E:E, Sales!B:B, "West") - GETPIVOTDATA("Revenue", Pivot!A1, "Region", "West")A result of 0 means the two agree. Any other value is the amount the pivot table is off by.
Adding more conditions
Each extra condition is another pair of arguments, and all conditions must be true for a row to count. To check West revenue for one product, use this formula:
=SUMIFS(Sales!E:E, Sales!B:B, "West", Sales!C:C, "Widget")This matches a pivot table with Region in Rows and Product in Columns, where you read the West and Widget intersection.
Checking dates
When your pivot table groups dates by month or year, use comparison operators inside quotes and join them to a date with &. This formula checks the total for 2026:
=SUMIFS(Sales!E:E, Sales!A:A, ">=" & DATE(2026,1,1), Sales!A:A, "<" & DATE(2027,1,1))Using a half-open range (on or after the start, before the next start) avoids mistakes with the last day of the period.
Behavior to know
- Text criteria are not case-sensitive. "west" matches "West".
- A criterion of
"West"matches whole cell contents. For partial matches, use wildcards such as"We*". SUMIFSignores cells in the sum range that contain text. If Revenue was imported as text, the formula returns a smaller total than expected, and the pivot table may show a count in place of a sum. A large gap between yourSUMIFSresult and the pivot sum often means this.- Trailing spaces make "West " a different value from "West". The pivot table will list them as two separate rows, and
SUMIFSwith"West"will match only the clean one.
Rebuilding the whole table with QUERY
SUMIFS checks one cell at a time. QUERY can rebuild the full summary in one formula. It takes a data range, a query string written in a small SQL-like language, and the number of header rows.
=QUERY(Sales!A1:E, "select B, sum(E) where B is not null group by B label sum(E) 'Total revenue'", 1)Here is how each part works:
select B, sum(E)returns the region and the summed revenue.where B is not nullremoves rows with no region, so blanks do not form their own group.group by Bcreates one output row per region, like putting Region in Rows.label sum(E) 'Total revenue'renames the output column.- The final
1says the range has one header row.
Column letters in a query string refer to positions in the range you pass in, not to letters on the sheet. If your range starts at column A, the two match. If you pass Sales!C1:E, then C is the first column of the range, and you must write Col1, Col2 and so on instead of letters, or adjust your query to match the range.
Mimicking a Columns field
A pivot table with a field in Columns corresponds to the pivot clause in QUERY:
=QUERY(Sales!A1:E, "select B, sum(E) where B is not null group by B pivot C", 1)This returns one row per region and one column per product, as a pivot table with Region in Rows and Product in Columns would.
Mimicking filters and counts
A pivot table filter becomes a where condition. This query limits the summary to rows with at least one unit:
=QUERY(Sales!A1:E, "select B, sum(E), count(E) where B is not null and D > 0 group by B", 1)Here count(E) counts non-empty numeric revenue cells, which you can compare with a pivot table using COUNT as its summary function.
Comparing the whole table
You can compare two tables cell by cell with an array formula. If the pivot table sits at Pivot!A1 and the QUERY result is on a sheet named Check starting at A1, this formula flags any mismatch:
=ARRAYFORMULA(IF(Check!B2:B6 = Pivot!B3:B7, "OK", "Differs"))Adjust the ranges to match your layout. The pivot table usually has a title row and a header row, so its first data row is further down than the QUERY output. Check that rows line up by region before you trust the comparison.
SUMIFS or QUERY: choosing one
| Situation | Better choice |
|---|---|
| Verify a single number in the pivot table | `SUMIFS` |
| Verify every row and column of the summary | `QUERY` |
| Need a live report you control fully | `QUERY` |
| Conditions on several columns, one result cell | `SUMIFS` |
| Need counts, averages and sums together | `QUERY` |
Both are formulas, so they update when the source data changes. Open-ended ranges such as Sales!E:E and Sales!A1:E include new rows automatically, which is also why they work well for catching a stale pivot source range.
When the numbers do not match
Work through these causes in order. Each takes only a moment to check.
- Open the pivot table editor and confirm the source range covers every row. A stale range is the most common cause.
- Check the Filters section. A filter on Region or Date hides records that
SUMIFSstill counts. - Check Summarize by. COUNTA and SUM give very different results on the same column.
- Look for text-formatted numbers. Use
=COUNT(Sales!E2:E)and compare it with=COUNTA(Sales!E2:E). If the second number is larger, some revenue cells are text. - Look for hidden spaces or spelling variants in Region, such as "West" and "West ". Test with
=SUMPRODUCT(LEN(Sales!B2:B)<>LEN(TRIM(Sales!B2:B))), which counts cells with extra spaces.
Worked example
Suppose the pivot table shows West revenue of 41,200, and your SUMIFS formula returns 43,700. The difference is 2,500.
- The pivot source range is
Sales!A1:E200, and the sheet now has 215 rows. Extending the range may fix part of the gap. - After extending the range, the pivot shows 43,700. The two now agree.
If the numbers still differed, the next step would be to look at the Filters section, then at text values, in that order.
Exercise
A pivot table shows Revenue for the North region as 18,000. =SUMIFS(Sales!E:E, Sales!B:B, "North") returns 21,500. The pivot source range covers every row and there are no filters. =COUNT(Sales!E2:E) returns 180 and =COUNTA(Sales!E2:E) returns 180. What should you check next, and which QUERY formula would show all regions side by side to locate the problem?
Show answer
Check the Summarize by setting for Revenue, since the data is clean (COUNT equals COUNTA, so no text numbers) and the range and filters are fine. It may be set to something other than SUM, such as AVERAGE or MAX. Also check for "North " with a trailing space, which would split into a separate pivot row. To compare every region, use =QUERY(Sales!A1:E, "select B, sum(E) where B is not null group by B label sum(E) 'Total revenue'", 1) and compare each row with the pivot table.