{"record":{"id":"e783096f3778e2d5","repo":"PHPOffice/PhpSpreadsheet","slug":"a-pivot-table-requires-at-least-one-data-value-f","errorCode":null,"errorMessage":"A pivot table requires at least one data (value) field","messagePattern":"A pivot table requires at least one data \\(value\\) field","errorType":"exception","errorClass":"PhpOffice\\PhpSpreadsheet\\Exception","httpStatus":null,"severity":"error","filePath":"src/PhpSpreadsheet/Worksheet/PivotTable/PivotTableBuilder.php","lineNumber":198,"sourceCode":"        return $this;\n    }\n\n    private function assertFieldExists(string $fieldName): void\n    {\n        if (!in_array($fieldName, $this->fieldNames, true)) {\n            throw new PhpSpreadsheetException(\"Pivot source field '{$fieldName}' does not exist in range {$this->sourceRange}\");\n        }\n    }\n\n    private function assertHasDataField(): void\n    {\n        foreach ($this->placements as $placement) {\n            if ($placement['axis'] === PivotField::AXIS_VALUES) {\n                return;\n            }\n        }\n\n        throw new PhpSpreadsheetException('A pivot table requires at least one data (value) field');\n    }\n\n    /**\n     * @return string[]\n     */\n    private function readHeaderNames(): array\n    {\n        [$start, $end] = Coordinate::rangeBoundaries($this->sourceRange);\n        $startColumn = (int) $start[0];\n        $endColumn = (int) $end[0];\n        $headerRow = (int) $start[1];\n        $names = [];\n        for ($col = $startColumn; $col <= $endColumn; ++$col) {\n            $cell = Coordinate::stringFromColumnIndex($col) . $headerRow;\n            $names[] = $this->sourceWorksheet->getCell($cell)->getValueString();\n        }\n\n        return $names;","sourceCodeStart":180,"sourceCodeEnd":216,"githubUrl":"https://github.com/PHPOffice/PhpSpreadsheet/blob/65b080eef4d9fd11a5796135ab145883e5c3d6a6/src/PhpSpreadsheet/Worksheet/PivotTable/PivotTableBuilder.php#L180-L216","documentation":"Error \"A pivot table requires at least one data (value) field\" thrown in PHPOffice/PhpSpreadsheet.","triggerScenarios":"Thrown at src/PhpSpreadsheet/Worksheet/PivotTable/PivotTableBuilder.php:198 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"65b080eef4d9fd11a5796135ab145883e5c3d6a6","analyzedAt":"2026-08-17T05:40:41.646Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}