qax-os/excelize · error
data fields %s appear both in the pivot table column fields
Error message
data fields %s appear both in the pivot table column fields and filter fields
What it means
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.
Source
Thrown at errors.go:351
return fmt.Errorf("slicer %s does not exist", name)
}
// newNoExistTableError defined the error message on receiving the non existing
// table name.
func newNoExistTableError(name string) error {
return fmt.Errorf("table %s does not exist", name)
}
// newNotWorksheetError defined the error message on receiving a sheet which
// not a worksheet.
func newNotWorksheetError(name string) error {
return fmt.Errorf("sheet %s is not a worksheet", name)
}
// newPivotTableColFieldsError defined the error message on same data field
// appears both in the pivot table column fields and filter fields.
func newPivotTableColFieldsError(data []string) error {
return fmt.Errorf("data fields %s appear both in the pivot table column fields and filter fields", strings.Join(data, ", "))
}
// newPivotTableRowFieldsError defined the error message on same data field
// appears both in the pivot table row fields and filter fields.
func newPivotTableRowFieldsError(data []string) error {
return fmt.Errorf("data fields %s appear both in the pivot table row fields and filter fields", strings.Join(data, ", "))
}
// newPivotTableDataRangeError defined the error message on receiving the
// invalid pivot table data range.
func newPivotTableDataRangeError(msg string) error {
return fmt.Errorf("parameter 'DataRange' parsing error: %s", msg)
}
// newPivotTableSelectedItemError defined the error message on receiving the
// invalid pivot table selected item.
func newPivotTableSelectedItemError(item, field string) error {
return fmt.Errorf("selected item %s does not exist in pivot table field %s", item, field)View on GitHub (pinned to f2483381fb)
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
Example fix
// before
Columns: []PivotTableField{{Data: "Region"}},
Filters: []PivotTableField{{Data: "Region"}},
// after
Columns: []PivotTableField{},
Filters: []PivotTableField{{Data: "Region"}}, Defensive patterns
Strategy: validation
Validate before calling
func validatePivotAreas(o *excelize.Options) error {
cols := map[string]bool{}
for _, f := range o.PivotTableColumnFields { cols[f.Data] = true }
for _, f := range o.PivotTableFilterFields {
if cols[f.Data] {
return fmt.Errorf("field %q in both columns and filters", f.Data)
}
}
return nil
} Type guard
null
Try / catch
if err := f.AddPivotTable("Sheet1!A1:E10", "Sheet1!G2", opts); err != nil {
if strings.Contains(err.Error(), "column fields and filter fields") {
return fmt.Errorf("bad pivot config: %w", err)
}
return err
} Prevention
- 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
When it happens
Trigger: Calling f.AddPivotTable with Options whose PivotTableColumnFields and PivotTableFilterFields both contain the same field name (detected in parseFormatPivotTableSet or TestPivotTable).
Common situations: 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.
Related errors
- data fields %s appear both in the pivot table row fields and
- the value of UnzipSizeLimit should be greater than or equal
- ErrParameterRequired
- ErrPivotTableShowValuesAsBaseField
- ErrPivotTableShowValuesAsBaseItem
AI-assisted analysis of qax-os/excelize@f2483381fb (2026-09-02).
Data as JSON: /api/errors/1c099e28b4eeb46a.
Report an issue: GitHub.