{"record":{"id":"75a9c32a09356126","repo":"qax-os/excelize","slug":"errpivottableshowvaluesasbaseitem","errorCode":"ErrPivotTableShowValuesAsBaseItem","errorMessage":"this kind of show values as type and base field requires a base item","messagePattern":"this kind of show values as type and base field requires a base item","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"errors.go","lineNumber":135,"sourceCode":"\tErrOutlineLevel = errors.New(\"invalid outline level\")\n\t// ErrPageSetupAdjustTo defined the error message for receiving a page setup\n\t// adjust to value exceeds limit.\n\tErrPageSetupAdjustTo = errors.New(\"adjust to value must be an integer from 0 to 400\")\n\t// ErrParameterInvalid defined the error message on receive the invalid\n\t// parameter.\n\tErrParameterInvalid = errors.New(\"parameter is invalid\")\n\t// ErrParameterRequired defined the error message on receive the empty\n\t// parameter.\n\tErrParameterRequired = errors.New(\"parameter is required\")\n\t// ErrPasswordLengthInvalid defined the error message on invalid password\n\t// length.\n\tErrPasswordLengthInvalid = errors.New(\"password length invalid\")\n\t// ErrPivotTableShowValuesAsBaseField defined the error message on enable\n\t// this kind of \"show values as\" type requires a base field.\n\tErrPivotTableShowValuesAsBaseField = errors.New(\"this kind of show values as type requires a base field\")\n\t// ErrPivotTableShowValuesAsBaseItem defined the error message on enable\n\t// this kind of \"show values as\" type and base field requires a base item.\n\tErrPivotTableShowValuesAsBaseItem = errors.New(\"this kind of show values as type and base field requires a base item\")\n\t// ErrPivotTableClassicLayout defined the error message on enable\n\t// ClassicLayout and CompactData in the same time.\n\tErrPivotTableClassicLayout = errors.New(\"cannot enable ClassicLayout and CompactData in the same time\")\n\t// ErrSave defined the error message for saving file.\n\tErrSave = errors.New(\"no path defined for file, consider File.WriteTo or File.Write\")\n\t// ErrSheetIdx defined the error message on receive the invalid worksheet\n\t// index.\n\tErrSheetIdx = errors.New(\"invalid worksheet index\")\n\t// ErrSheetNameBlank defined the error message on receive the blank sheet\n\t// name.\n\tErrSheetNameBlank = errors.New(\"the sheet name can not be blank\")\n\t// ErrSheetNameInvalid defined the error message on receive the sheet name\n\t// contains invalid characters.\n\tErrSheetNameInvalid = errors.New(\"the sheet can not contain any of the characters :\\\\/?*[or]\")\n\t// ErrSheetNameLength defined the error message on receiving the sheet\n\t// name length exceeds the limit.\n\tErrSheetNameLength = fmt.Errorf(\"the sheet name length exceeds the %d characters limit\", MaxSheetNameLength)\n\t// ErrSheetNameSingleQuote defined the error message on the first or last","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/qax-os/excelize/blob/f2483381fbfbe432a6baa98d48a1c277183f3285/errors.go#L117-L153","documentation":"ErrPivotTableShowValuesAsBaseItem is returned when a pivot table data field's \"show values as\" configuration specifies a BaseField but the required BaseItem is empty. The base item names the specific item of the base field to compare against.","triggerScenarios":"f.AddPivotTable with opts.Data[i].ShowValuesAs having BaseField set but BaseItem == \"\"; setPivotTableShowValuesAsBaseItem (pivotTable.go:947) returns it when baseItem is empty, before validating the item against shared items.","commonSituations":"Setting BaseField but forgetting BaseItem when building options; BaseItem sourced from config/user input that is empty; misunderstanding that both base field AND base item are needed for certain ShowValuesAs types.","solutions":["Set ShowValuesAs.BaseItem to an item that exists under the base field, e.g. \"2023\"","Verify the item name exactly matches a shared item of the base field","Only enable ShowValuesAs types requiring a base item when both values are known"],"exampleFix":"// before\nShowValuesAs: excelize.PivotTableShowValuesAs{Type: \"percentDifferenceOf\", BaseField: \"Year\"}\n// after\nShowValuesAs: excelize.PivotTableShowValuesAs{Type: \"percentDifferenceOf\", BaseField: \"Year\", BaseItem: \"2023\"}","handlingStrategy":"validation","validationCode":"for _, d := range opts.Data {\n    if d.ShowValuesAs.BaseField != \"\" && d.ShowValuesAs.BaseItem == \"\" {\n        return errors.New(\"ShowValuesAs requires BaseItem\")\n    }\n}\nerr := f.AddPivotTable(opts)","typeGuard":"func needsBaseItem(sv excelize.PivotTableShowValuesAs) bool { return sv.BaseField != \"\" && sv.BaseItem == \"\" }","tryCatchPattern":"if err := f.AddPivotTable(opts); errors.Is(err, excelize.ErrPivotTableShowValuesAsBaseItem) { // set BaseItem and retry }","preventionTips":["Always set BaseItem together with BaseField for ShowValuesAs types that need it","Verify BaseItem matches an existing item of the base field","Reject empty config-sourced item names early"],"tags":["go","excelize","pivot-table","missing-parameter"],"backgroundTag":"missing-required-argument","analyzedSha":"f2483381fbfbe432a6baa98d48a1c277183f3285","analyzedAt":"2026-09-02T01:26:19.299Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}