{"record":{"id":"f75f36f8bf187f98","repo":"qax-os/excelize","slug":"base-field-s-does-not-exist-in-shared-items","errorCode":null,"errorMessage":"base field %s does not exist in shared items","messagePattern":"base field (.+?) does not exist in shared items","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"errors.go","lineNumber":381,"sourceCode":"\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)\n}\n\n// newStreamSetRowOrderError defined the error message on calling the SetRow\n// function before the order function.\nfunc newStreamSetRowOrderError(name string) error {\n\treturn fmt.Errorf(\"must call the %s function before the SetRow function\", name)\n}\n\n// newUnknownFilterTokenError defined the error message on receiving a unknown\n// filter operator token.\nfunc newUnknownFilterTokenError(token string) error {\n\treturn fmt.Errorf(\"unknown operator: %s\", token)","sourceCodeStart":363,"sourceCodeEnd":399,"githubUrl":"https://github.com/qax-os/excelize/blob/f2483381fbfbe432a6baa98d48a1c277183f3285/errors.go#L363-L399","documentation":"Excelize throws this when a pivot table field named as the 'ShowValuesAs' base field cannot be found among the shared items of the pivot cache. ShowValuesAs calculations such as %Difference From or % of require a base field that already exists in the source data's shared item list.","triggerScenarios":"Calling f.SetPivotTableShowValuesAs (or setting ShowValuesAs in PivotTableOptions with a BaseField) where BaseField names a column/field that has no matching shared item in the pivot cache built from the DataRange.","commonSituations":"Typo in the field name (case-sensitive match against the header text); renaming a column in the source data after building the pivot definition; referencing a field that was filtered out or not included in the data range.","solutions":["Set BaseField to the exact header text of a column inside DataRange, matching case and spacing.","Re-check the source DataRange: if the header row was moved or the range shifted, rebuild the PivotTableOptions.","Verify the field appears in the Fields list of the same PivotTableOptions and its values were actually cached.","Inspect the generated pivot cache (sharedItems in xl/pivotCache/) if you need to confirm available field names."],"exampleFix":"// before\nopts.ShowValuesAs = &excelize.PivotTableShowValuesAs{\n    BaseField: \"Sales Amt\",\n}\n// after (header in DataRange is \"Sales Amount\")\nopts.ShowValuesAs = &excelize.PivotTableShowValuesAs{\n    BaseField: \"Sales Amount\",\n}","handlingStrategy":"validation","validationCode":"func fieldInDataRange(f *excelize.File, sheet, dataRange, field string) bool {\n    // header row of DataRange must contain the field name exactly\n    rows, err := f.GetRows(sheet)\n    if err != nil || len(rows) == 0 {\n        return false\n    }\n    for _, h := range rows[0] {\n        if h == field {\n            return true\n        }\n    }\n    return false\n}\n// before SetPivotTableShowValuesAs: check BaseField against headers of DataRange","typeGuard":null,"tryCatchPattern":"err := f.SetPivotTableShowValuesAs(sheet, cell, opts)\nif err != nil {\n    if strings.Contains(err.Error(), \"does not exist in shared items\") {\n        return fmt.Errorf(\"pivot ShowValuesAs base field %q not found in data range\", opts.ShowValuesAs.BaseField)\n    }\n    return err\n}","preventionTips":["Copy BaseField values from header cells, never type them by hand","Centralize field-name constants shared between headers and pivot options","Rebuild pivot options whenever the source data layout changes","Match case and whitespace exactly as written in the header row"],"tags":["go","excelize","pivot-table","field-name"],"backgroundTag":"pivot-base-field-not-found","analyzedSha":"f2483381fbfbe432a6baa98d48a1c277183f3285","analyzedAt":"2026-09-02T01:26:19.299Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}