qax-os/excelize · error
selected item %s does not exist in pivot table field %s
Error message
selected item %s does not exist in pivot table field %s
What it means
Returned by newPivotTableSelectedItemError when an item given in a pivot table field's selected-item list (or a slicer selection) does not exist among the values of that field within the pivot table's data. The library validates each requested item against the actual field members in checkSelectedItems.
Source
Thrown at errors.go:369
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)
}
// newPivotTableShowValuesAsBaseFieldError defined the error message on receiving
// the invalid pivot table "show values as" base field.
func newPivotTableShowValuesAsBaseFieldError(field string) error {
return fmt.Errorf("base field %s does not exist in shared items", field)
}
// newStreamSetRowError defined the error message on the stream writer
// receiving the non-ascending row number.
func newStreamSetRowError(row int) error {
return fmt.Errorf("row %d has already been written", row)View on GitHub (pinned to f2483381fb)
Solutions
- Check the exact item text in the source data range and correct the Selected value (case/whitespace included)
- Derive item names dynamically from the data range instead of hard-coding them
- Verify the Selected item belongs to the field you specified (not a different field)
- Re-check slicer configuration matches the pivot table's field and items
Example fix
// before
Fields: []Field{{Data: "Region", Selected: []string{"EMEA", "APAC"}}}, // APAC not in data
// after
Fields: []Field{{Data: "Region", Selected: []string{"EMEA", "Americas"}}}, // names taken from actual data Defensive patterns
Strategy: validation
Validate before calling
func validItems(f *excelize.File, sheet string, col int, selected []string) error {
rows, _ := f.GetRows(sheet)
seen := map[string]bool{}
for i, r := range rows {
if i > 0 && col < len(r) { seen[strings.TrimSpace(r[col])] = true }
}
for _, s := range selected {
if !seen[strings.TrimSpace(s)] {
return fmt.Errorf("item %q not in field data", s)
}
}
return nil
} Type guard
null
Try / catch
if err := f.AddPivotTable(dataRange, pivotRange, opts); err != nil {
if strings.Contains(err.Error(), "does not exist in pivot table field") {
return fmt.Errorf("refresh selection against source data: %w", err)
}
return err
} Prevention
- Derive Selected items from the source data at runtime instead of hard-coding
- Trim and normalize casing of item names before setting them
- Re-validate selections after any change to the source data range
- Ensure slicer selections reference the correct field of the pivot table
When it happens
Trigger: Setting a PivotTableOption/field Selected entry, or configuring a slicer, with an item string that is absent from the field's data (typo, changed data, item removed after data refresh).
Common situations: Hard-coded filter selections that no longer match refreshed source data; case-sensitive mismatches ("N/A" vs "n/a") or trailing whitespace; slicer options referencing fields/items from a different pivot table.
Related errors
- ErrParameterRequired
- ErrPivotTableShowValuesAsBaseField
- ErrPivotTableShowValuesAsBaseItem
- ErrPivotTableClassicLayout
- ErrUnsupportedPivotTableShowValuesAsType
AI-assisted analysis of qax-os/excelize@f2483381fb (2026-09-02).
Data as JSON: /api/errors/60db13d95f2e5120.
Report an issue: GitHub.