{"record":{"id":"ccef71d26bcd8936","repo":"qax-os/excelize","slug":"errpivottableshowvaluesasbasefield","errorCode":"ErrPivotTableShowValuesAsBaseField","errorMessage":"this kind of show values as type requires a base field","messagePattern":"this kind of show values as type requires a base field","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"errors.go","lineNumber":132,"sourceCode":"\tErrOptionsUnzipSizeLimit = errors.New(\"the value of UnzipSizeLimit should be greater than or equal to UnzipXMLSizeLimit\")\n\t// ErrOutlineLevel defined the error message on receive an invalid outline\n\t// level number.\n\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","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/qax-os/excelize/blob/f2483381fbfbe432a6baa98d48a1c277183f3285/errors.go#L114-L150","documentation":"ErrPivotTableShowValuesAsBaseField is returned when a pivot table data field uses a \"show values as\" calculation that requires a BaseField, but BaseField is an empty string. The base field identifies the field against which values are shown.","triggerScenarios":"Adding a pivot table via f.AddPivotTable where opts.Data[i].ShowValuesAs has a type that requires a base field (e.g. percent difference of) while ShowValuesAs.BaseField == \"\".","commonSituations":"Constructing PivotTableOptions programmatically and forgetting the BaseField; copying options and dropping the nested ShowValuesAs settings; using ShowValuesAs types without realizing some require base field/item.","solutions":["Set ShowValuesAs.BaseField to a field name present in DataRange, e.g. \"Year\"","Choose a ShowValuesAs type that does not require a base field, or drop ShowValuesAs","Validate Data[i].ShowValuesAs before calling AddPivotTable"],"exampleFix":"// before\nData: []excelize.PivotTableDataField{{Data: \"Sales\", ShowValuesAs: excelize.PivotTableShowValuesAs{Type: \"percentDifferenceOf\"}}}\n// after\nData: []excelize.PivotTableDataField{{Data: \"Sales\", ShowValuesAs: excelize.PivotTableShowValuesAs{Type: \"percentDifferenceOf\", BaseField: \"Year\", BaseItem: \"2023\"}}}","handlingStrategy":"validation","validationCode":"for _, d := range opts.Data {\n    if d.ShowValuesAs.Type != \"\" && d.ShowValuesAs.BaseField == \"\" {\n        return errors.New(\"ShowValuesAs requires BaseField\")\n    }\n}\nerr := f.AddPivotTable(opts)","typeGuard":"func needsBaseField(sv excelize.PivotTableShowValuesAs) bool { return sv.Type != \"\" && sv.BaseField == \"\" }","tryCatchPattern":"if err := f.AddPivotTable(opts); errors.Is(err, excelize.ErrPivotTableShowValuesAsBaseField) { // set BaseField and retry }","preventionTips":["Set BaseField whenever ShowValuesAs.Type is used","Ensure BaseField names a field within DataRange","Validate Data fields before AddPivotTable"],"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"}