{"record":{"id":"1c099e28b4eeb46a","repo":"qax-os/excelize","slug":"data-fields-s-appear-both-in-the-pivot-table-colu","errorCode":null,"errorMessage":"data fields %s appear both in the pivot table column fields and filter fields","messagePattern":"data fields (.+?) appear both in the pivot table column fields and filter fields","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"errors.go","lineNumber":351,"sourceCode":"\treturn fmt.Errorf(\"slicer %s does not exist\", name)\n}\n\n// newNoExistTableError defined the error message on receiving the non existing\n// table name.\nfunc newNoExistTableError(name string) error {\n\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)","sourceCodeStart":333,"sourceCodeEnd":369,"githubUrl":"https://github.com/qax-os/excelize/blob/f2483381fbfbe432a6baa98d48a1c277183f3285/errors.go#L333-L369","documentation":"Returned by newPivotTableColFieldsError when the same data field is listed in both PivotTableColumnFields and PivotTableFilterFields of a pivot table definition. A pivot table field can occupy only one area (row, column, filter, or data), so the library rejects the ambiguous configuration during parseFormatPivotTableSet.","triggerScenarios":"Calling f.AddPivotTable with Options whose PivotTableColumnFields and PivotTableFilterFields both contain the same field name (detected in parseFormatPivotTableSet or TestPivotTable).","commonSituations":"Building pivot options programmatically where fields are appended to multiple lists without deduplication; copy-pasted option structs where a field was moved from a column to a filter but not removed from the original list.","solutions":["Remove the duplicated field from one of the two lists (usually keep it in FilterFields and drop it from ColumnFields, or vice versa)","Deduplicate/validate the field slices before calling AddPivotTable","Run TestPivotTable on your options to catch the conflict early"],"exampleFix":"// before\nColumns: []PivotTableField{{Data: \"Region\"}},\nFilters: []PivotTableField{{Data: \"Region\"}},\n// after\nColumns: []PivotTableField{},\nFilters: []PivotTableField{{Data: \"Region\"}},","handlingStrategy":"validation","validationCode":"func validatePivotAreas(o *excelize.Options) error {\n    cols := map[string]bool{}\n    for _, f := range o.PivotTableColumnFields { cols[f.Data] = true }\n    for _, f := range o.PivotTableFilterFields {\n        if cols[f.Data] {\n            return fmt.Errorf(\"field %q in both columns and filters\", f.Data)\n        }\n    }\n    return nil\n}","typeGuard":"null","tryCatchPattern":"if err := f.AddPivotTable(\"Sheet1!A1:E10\", \"Sheet1!G2\", opts); err != nil {\n    if strings.Contains(err.Error(), \"column fields and filter fields\") {\n        return fmt.Errorf(\"bad pivot config: %w\", err)\n    }\n    return err\n}","preventionTips":["Build row/column/filter field lists from a single source of truth with an 'area' attribute per field","Deduplicate field names across all area lists before calling AddPivotTable","Add a unit test using TestPivotTable for every pivot layout you ship"],"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"}