qax-os/excelize · error

base field %s does not exist in shared items

Error message

base field %s does not exist in shared items

What it means

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.

Source

Thrown at errors.go:381

	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)
}

// newStreamSetRowOrderError defined the error message on calling the SetRow
// function before the order function.
func newStreamSetRowOrderError(name string) error {
	return fmt.Errorf("must call the %s function before the SetRow function", name)
}

// newUnknownFilterTokenError defined the error message on receiving a unknown
// filter operator token.
func newUnknownFilterTokenError(token string) error {
	return fmt.Errorf("unknown operator: %s", token)

View on GitHub (pinned to f2483381fb)

Solutions

  1. Set BaseField to the exact header text of a column inside DataRange, matching case and spacing.
  2. Re-check the source DataRange: if the header row was moved or the range shifted, rebuild the PivotTableOptions.
  3. Verify the field appears in the Fields list of the same PivotTableOptions and its values were actually cached.
  4. Inspect the generated pivot cache (sharedItems in xl/pivotCache/) if you need to confirm available field names.

Example fix

// before
opts.ShowValuesAs = &excelize.PivotTableShowValuesAs{
    BaseField: "Sales Amt",
}
// after (header in DataRange is "Sales Amount")
opts.ShowValuesAs = &excelize.PivotTableShowValuesAs{
    BaseField: "Sales Amount",
}
Defensive patterns

Strategy: validation

Validate before calling

func fieldInDataRange(f *excelize.File, sheet, dataRange, field string) bool {
    // header row of DataRange must contain the field name exactly
    rows, err := f.GetRows(sheet)
    if err != nil || len(rows) == 0 {
        return false
    }
    for _, h := range rows[0] {
        if h == field {
            return true
        }
    }
    return false
}
// before SetPivotTableShowValuesAs: check BaseField against headers of DataRange

Try / catch

err := f.SetPivotTableShowValuesAs(sheet, cell, opts)
if err != nil {
    if strings.Contains(err.Error(), "does not exist in shared items") {
        return fmt.Errorf("pivot ShowValuesAs base field %q not found in data range", opts.ShowValuesAs.BaseField)
    }
    return err
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of qax-os/excelize@f2483381fb (2026-09-02). Data as JSON: /api/errors/f75f36f8bf187f98. Report an issue: GitHub.