{"record":{"id":"60db13d95f2e5120","repo":"qax-os/excelize","slug":"selected-item-s-does-not-exist-in-pivot-table-fie","errorCode":null,"errorMessage":"selected item %s does not exist in pivot table field %s","messagePattern":"selected item (.+?) does not exist in pivot table field (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"errors.go","lineNumber":369,"sourceCode":"\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)\n}\n\n// newPivotTableShowValuesAsBaseFieldError defined the error message on receiving\n// the invalid pivot table \"show values as\" base field.\nfunc newPivotTableShowValuesAsBaseFieldError(field string) error {\n\treturn fmt.Errorf(\"base field %s does not exist in shared items\", field)\n}\n\n// newStreamSetRowError defined the error message on the stream writer\n// receiving the non-ascending row number.\nfunc newStreamSetRowError(row int) error {\n\treturn fmt.Errorf(\"row %d has already been written\", row)","sourceCodeStart":351,"sourceCodeEnd":387,"githubUrl":"https://github.com/qax-os/excelize/blob/f2483381fbfbe432a6baa98d48a1c277183f3285/errors.go#L351-L387","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"// before\nFields: []Field{{Data: \"Region\", Selected: []string{\"EMEA\", \"APAC\"}}}, // APAC not in data\n// after\nFields: []Field{{Data: \"Region\", Selected: []string{\"EMEA\", \"Americas\"}}}, // names taken from actual data","handlingStrategy":"validation","validationCode":"func validItems(f *excelize.File, sheet string, col int, selected []string) error {\n    rows, _ := f.GetRows(sheet)\n    seen := map[string]bool{}\n    for i, r := range rows {\n        if i > 0 && col < len(r) { seen[strings.TrimSpace(r[col])] = true }\n    }\n    for _, s := range selected {\n        if !seen[strings.TrimSpace(s)] {\n            return fmt.Errorf(\"item %q not in field data\", s)\n        }\n    }\n    return nil\n}","typeGuard":"null","tryCatchPattern":"if err := f.AddPivotTable(dataRange, pivotRange, opts); err != nil {\n    if strings.Contains(err.Error(), \"does not exist in pivot table field\") {\n        return fmt.Errorf(\"refresh selection against source data: %w\", err)\n    }\n    return err\n}","preventionTips":["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"],"tags":["go","excelize","pivot-table","slicer"],"backgroundTag":"invalid-pivot-field-item","analyzedSha":"f2483381fbfbe432a6baa98d48a1c277183f3285","analyzedAt":"2026-09-02T01:26:19.299Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}