qax-os/excelize · error

data fields %s appear both in the pivot table row fields and

Error message

data fields %s appear both in the pivot table row fields and filter fields

What it means

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.

Source

Thrown at errors.go:357

	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)
}

// newPivotTableRangeError defined the error message on receiving the invalid
// pivot table range.
func newPivotTableRangeError(msg string) error {
	return fmt.Errorf("parameter 'PivotTableRange' parsing error: %s", msg)

View on GitHub (pinned to f2483381fb)

Solutions

  1. Remove the field from either Rows or Filters so it appears in only one area
  2. Validate the option structs for duplicate field names before calling AddPivotTable
  3. Use TestPivotTable in tests to detect invalid layouts before writing files

Example fix

// before
Rows:    []PivotTableField{{Data: "Category"}},
Filters: []PivotTableField{{Data: "Category"}},
// after
Rows:    []PivotTableField{{Data: "Category"}},
Filters: []PivotTableField{},
Defensive patterns

Strategy: validation

Validate before calling

func validatePivotAreas(o *excelize.Options) error {
    rows := map[string]bool{}
    for _, f := range o.PivotTableRowFields { rows[f.Data] = true }
    for _, f := range o.PivotTableFilterFields {
        if rows[f.Data] {
            return fmt.Errorf("field %q in both rows and filters", f.Data)
        }
    }
    return nil
}

Type guard

null

Try / catch

if err := f.AddPivotTable(dataRange, pivotRange, opts); err != nil {
    if strings.Contains(err.Error(), "row fields and filter fields") {
        return fmt.Errorf("bad pivot config: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: Calling f.AddPivotTable with Options where a field name occurs in both PivotTableRowFields and PivotTableFilterFields (also surfaced via TestPivotTable).

Common situations: 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.

Related errors


AI-assisted analysis of qax-os/excelize@f2483381fb (2026-09-02). Data as JSON: /api/errors/d3b878b42fa23846. Report an issue: GitHub.