Sub topic 1
Start with clean source data
Grouping and calculated fields both read your source range directly. A pivot table does not repair the data it is given. If a date is stored as text, a date group cannot be built. If a header is duplicated, a calculated field cannot tell which column you mean. This chapter covers how to prepare a source range so the later chapters work the first time.
Prerequisites
This chapter assumes you can do the following:
- Move around Google Sheets, select ranges, and enter cell formulas such as
=SUM(D2:D6). - Organize data as a table with one header row and one record per row.
- Summarize data with SUM, COUNT and AVERAGE, and you know roughly what a pivot table is.
You do not need to have used grouping or calculated fields. The next chapter recaps the pivot editor, so it is fine if you have only built a simple pivot table before.
Why the source matters more for grouping
A basic pivot table is forgiving. It will list whatever text it finds in a column and sum whatever numbers it finds in another. Grouping and calculated fields are less forgiving, for these reasons:
- Date groups need real date values. They work on the underlying date serial number, and the option to group by month or quarter is offered only when Sheets recognizes the value as a date.
- Numeric interval groups need real numbers. A number stored as text is treated as a label, so there is nothing to bucket.
- Calculated fields refer to columns by header name. The header text is the identifier, so it must be unique and stable.
- Manual groups pick items by their displayed label. If
WestandWest(with a trailing space) both appear, you will see two items where you expected one.
Most problems later in the tutorial trace back to one of these causes. Fixing the source takes a few minutes, and diagnosing a broken pivot afterwards usually takes longer.
The running example
The rest of the tutorial uses this small table. Paste it into a sheet starting at A1, with each value in its own cell. The columns are tab separated, so pasting the text should split them correctly.
Date Region Product Units Revenue Cost
2026-01-05 West Widget 10 250 150
2026-01-19 East Widget 4 100 60
2026-02-02 West Gadget 7 420 245
2026-02-23 South Gadget 3 180 105
2026-03-09 East Gizmo 12 600 420This table has one header row, one record per row, and no blank rows or columns. Each column holds one kind of value: dates, text labels, or numbers. Those are the properties to aim for in your own data.
A checklist for a clean source range
The sections below take each check in turn.
1. One header row with unique, non-blank names
Every column needs a header in the first row of the range. The pivot editor lists these headers as the fields you can drag into Rows, Columns, Values and Filters. Calculated fields use the same names inside formulas, for example =Revenue - Cost.
Follow these rules:
- Give every column a header. Do not leave a header cell empty over a column you want to use.
- Keep headers unique. If two columns are both called
Amount, a formula cannot distinguish them. - Prefer short names without spaces, such as
UnitPriceorUnit_Price. A header that contains spaces still works, but in a calculated field it must be wrapped in single quotes, as in='Unit Price' * Quantity. Names without spaces avoid that extra quoting. - Put the headers in one row. Merged cells and two-row headers do not map cleanly onto fields.
- Decide on the final names before you write calculated fields. Renaming a header afterwards changes the field name, and formulas that used the old name can break.
2. One data type per column
A column should contain only one kind of value. A Units column that holds 10, 4, and n/a is partly text. The text entries are ignored by SUM, but they change how COUNT behaves and can stop the column being treated as numeric for grouping.
Sheets shows a value's type through its default alignment. Real numbers and dates are right-aligned and text is left-aligned, unless you changed the alignment. You can also test it directly. In a spare cell, enter:
=ARRAYFORMULA(ISNUMBER(A2:A6))Real dates and numbers return TRUE. Text that only looks like a date or number returns FALSE. Dates are numbers underneath, so ISNUMBER is a valid test for both.
3. Real dates, not text dates
This is the most common blocker for date grouping. A value like 2026-01-05 can be a true date or a text string, and the two look alike. Typical sources of text dates are:
- Data pasted from a CSV or a web page.
- Exports from other systems that use a format your spreadsheet locale does not recognize, for example
05.01.2026in a US-locale file. - Cells with a leading apostrophe or a Plain text number format.
To convert them, use DATEVALUE on the text. Place this formula in a helper column next to the original, assuming the dates start in A2:
=ARRAYFORMULA(IF(A2:A="",,DATEVALUE(A2:A)))Then format the helper column as a date (Format, Number, Date). When you are satisfied, copy the helper column and paste it over the original with Paste special, Values only, so the dates become fixed values rather than formulas. Alternatively, point the pivot table at the helper column.
DATEVALUE depends on your spreadsheet's locale (File, Settings). If it returns an error for some rows, those rows are in a format your locale does not recognize, and you will have to fix them or change the locale.
4. Real numbers, not text numbers
Numeric groups, SUM and calculated fields all need numbers. Text numbers come from the same sources as text dates, and also from currency symbols or thousands separators typed into a text cell. If ISNUMBER returns FALSE for a number column, convert it with VALUE:
=ARRAYFORMULA(IF(E2:E="",,VALUE(E2:E)))Keep units and symbols out of the data cells where you can. Store 250 and format the column as currency instead of storing the text $250 USD.
5. No blank rows, subtotal rows or notes inside the range
A pivot table summarizes every row in its source range. A Total row at the bottom is counted as a data row, so your pivot will double-count the revenue. A note typed into a column adds a stray item to the pivot rows. Blank rows in the middle of data create an item with no label, which shows up as an empty or (blank) entry.
Keep totals outside the range, or leave them out. Sheets can compute totals in the pivot itself.
Blank cells in the source behave differently by column role:
- A blank in a row or column field appears as a blank item. You can hide it in the editor by clearing its checkbox in the field's filter list.
- A blank in a value field is skipped by SUM and AVERAGE. COUNT counts only non-blank cells, so one blank changes the count.
- A blank in a date column cannot be placed in a date group. Fill the cell or remove the row.
Decide for each column whether a blank means "zero", "unknown" or "not applicable", and make the cell say so if the difference matters.
6. Consistent labels
Labels are compared as exact text. West, west and West can show up as separate items, and trailing spaces are invisible. Manual grouping, covered in a later chapter, is built on these labels, so inconsistent spelling forces you to group items that should have been the same item to begin with.
Clean text with TRIM and a consistent case function in a helper column:
=ARRAYFORMULA(IF(B2:B="",,PROPER(TRIM(B2:B))))TRIM removes leading and trailing spaces and collapses repeated spaces. PROPER standardizes capitalization. For repeated fixes, Data then Data cleanup offers tools such as Remove duplicates, Trim whitespace and Suggested cleanups.
Choosing the range
When you create a pivot table (Insert, Pivot table), Sheets asks for a data range. You have two main options:
| Range style | Example | Behavior when rows are added |
|---|---|---|
| Fixed range | `Data!A1:F6` | New rows below row 6 are not included until you extend the range. |
| Whole columns | `Data!A:F` | New rows are included automatically. |
Whole-column ranges are convenient for data that grows. They work well as long as nothing else sits below the table in those columns, because anything there is read as data. If you use a helper column for cleaning, make sure it is inside the range or that the pivot points at it, so the converted values are what the pivot reads.
If the range comes from a formula, such as QUERY or FILTER, check that the formula's output still has a single header row with unique names, because the pivot reads the output cells and not the formula.
Verify before you build
A short check on the running example takes less than a minute and avoids most surprises. In a scratch area, run these tests against the sample data:
=ARRAYFORMULA(ISNUMBER(A2:A6))
=COUNTA(A1:F1)
=COUNTA(A2:A)
=SUM(E2:E6)You should see all TRUE for the dates, 6 headers, 5 records, and 1550 for the revenue total. Keep that revenue figure. Later chapters group and calculate on this data, and the grand total in every pivot should match what the source gives you. A pivot table whose grand total disagrees with a direct SUM of the source has a data problem or a range problem.
Common mistakes
- Building the pivot first and cleaning later. The pivot reads the range when you create it, and a column whose type was wrong at that point may need its fields reset. Clean first.
- Fixing the displayed value instead of the stored value. Changing the number format of a text cell to Date does not convert the text. Convert with
DATEVALUEor re-enter the value. - Leaving subtotal rows in the range. The grand total of the pivot will be inflated by the amount of the subtotals.
- Changing headers after writing calculated fields. Rename headers before you write formulas.
- Assuming a blank equals zero. SUM skips blanks, but AVERAGE also skips them, so the average is computed over fewer rows than you may expect.
Exercise
You paste an export into a sheet. The Date column looks like 2026-04-12, but when you right-click a date in a pivot table row, no date grouping options appear. Name a formula that confirms the diagnosis, state what result confirms it, and give one way to fix the column.
Show answer
Use =ARRAYFORMULA(ISNUMBER(A2:A)), or ISNUMBER on a single cell. A result of FALSE confirms the values are text and not real dates. To fix it, convert them with =ARRAYFORMULA(IF(A2:A="",,DATEVALUE(A2:A))) in a helper column, format that column as Date, and either point the pivot at it or paste it over the original as values only. Then rebuild or refresh the pivot.
Exercise
A source table has a header Unit Price and another column Quantity. A colleague adds a final row labeled Total that sums each numeric column. What two problems does this cause for a pivot table built on the whole range, and how do you avoid each?
Show answer
First, the Total row is treated as a data record, so the pivot's grand total counts the amounts twice, and Total appears as an extra item in the row field. Remove the row from the range or move it outside the range. Second, the header Unit Price contains a space, so a calculated field must write it as ='Unit Price' * Quantity. You can avoid the quoting by renaming the header to UnitPrice before writing formulas.