{"record":{"id":"d3b878b42fa23846","repo":"qax-os/excelize","slug":"data-fields-s-appear-both-in-the-pivot-table-row","errorCode":null,"errorMessage":"data fields %s appear both in the pivot table row fields and filter fields","messagePattern":"data fields (.+?) appear both in the pivot table row fields and filter fields","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"errors.go","lineNumber":357,"sourceCode":"\treturn fmt.Errorf(\"table %s does not exist\", name)\n}\n\n// newNotWorksheetError defined the error message on receiving a sheet which\n// not a worksheet.\nfunc newNotWorksheetError(name string) error {\n\treturn fmt.Errorf(\"sheet %s is not a worksheet\", name)\n}\n\n// newPivotTableColFieldsError defined the error message on same data field\n// appears both in the pivot table column fields and filter fields.\nfunc newPivotTableColFieldsError(data []string) error {\n\treturn fmt.Errorf(\"data fields %s appear both in the pivot table column fields and filter fields\", strings.Join(data, \", \"))\n}\n\n// newPivotTableRowFieldsError defined the error message on same data field\n// appears both in the pivot table row fields and filter fields.\nfunc newPivotTableRowFieldsError(data []string) error {\n\treturn fmt.Errorf(\"data fields %s appear both in the pivot table row fields and filter fields\", strings.Join(data, \", \"))\n}\n\n// newPivotTableDataRangeError defined the error message on receiving the\n// invalid pivot table data range.\nfunc newPivotTableDataRangeError(msg string) error {\n\treturn fmt.Errorf(\"parameter 'DataRange' parsing error: %s\", msg)\n}\n\n// newPivotTableSelectedItemError defined the error message on receiving the\n// invalid pivot table selected item.\nfunc newPivotTableSelectedItemError(item, field string) error {\n\treturn fmt.Errorf(\"selected item %s does not exist in pivot table field %s\", item, field)\n}\n\n// newPivotTableRangeError defined the error message on receiving the invalid\n// pivot table range.\nfunc newPivotTableRangeError(msg string) error {\n\treturn fmt.Errorf(\"parameter 'PivotTableRange' parsing error: %s\", msg)","sourceCodeStart":339,"sourceCodeEnd":375,"githubUrl":"https://github.com/qax-os/excelize/blob/f2483381fbfbe432a6baa98d48a1c277183f3285/errors.go#L339-L375","documentation":"Returned by newPivotTableRowFieldsError when the same data field appears in both PivotTableRowFields and PivotTableFilterFields. Each pivot field must occupy exactly one area; the duplicate assignment is rejected while parsing the options in parseFormatPivotTableSet.","triggerScenarios":"Calling f.AddPivotTable with Options where a field name occurs in both PivotTableRowFields and PivotTableFilterFields (also surfaced via TestPivotTable).","commonSituations":"Generating row/filter lists from user selections or config without checking for overlaps; refactoring a pivot layout where a field moved to a filter but stayed in the rows list.","solutions":["Remove the field from either Rows or Filters so it appears in only one area","Validate the option structs for duplicate field names before calling AddPivotTable","Use TestPivotTable in tests to detect invalid layouts before writing files"],"exampleFix":"// before\nRows:    []PivotTableField{{Data: \"Category\"}},\nFilters: []PivotTableField{{Data: \"Category\"}},\n// after\nRows:    []PivotTableField{{Data: \"Category\"}},\nFilters: []PivotTableField{},","handlingStrategy":"validation","validationCode":"func validatePivotAreas(o *excelize.Options) error {\n    rows := map[string]bool{}\n    for _, f := range o.PivotTableRowFields { rows[f.Data] = true }\n    for _, f := range o.PivotTableFilterFields {\n        if rows[f.Data] {\n            return fmt.Errorf(\"field %q in both rows and filters\", f.Data)\n        }\n    }\n    return nil\n}","typeGuard":"null","tryCatchPattern":"if err := f.AddPivotTable(dataRange, pivotRange, opts); err != nil {\n    if strings.Contains(err.Error(), \"row fields and filter fields\") {\n        return fmt.Errorf(\"bad pivot config: %w\", err)\n    }\n    return err\n}","preventionTips":["Model pivot fields once with an explicit area enum (row|col|filter|data) instead of parallel slices","Deduplicate across Rows and Filters before calling AddPivotTable","Exercise options in tests with TestPivotTable"],"tags":["go","excelize","pivot-table","configuration"],"backgroundTag":"pivot-field-assignment-conflict","analyzedSha":"f2483381fbfbe432a6baa98d48a1c277183f3285","analyzedAt":"2026-09-02T01:26:19.299Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}