Budibase/budibase · error · HTTPError
Duplicate calculation on field "${schema.field}", calculatio
Error message
Duplicate calculation on field "${schema.field}", calculation type "${schema.calculationType}" What it means
Validation guard for calculation views: each non-count-distinct combination of target field and calculation type may appear only once across the view's calculation fields. A duplicate (same field, same calculationType) is rejected with 400.
Source
Thrown at packages/server/src/sdk/workspace/views/index.ts:112
const tableId = getTableIdFromViewId(viewId)
return !isExternalTableID(tableId)
}
function guardDuplicateCalculationFields(view: Omit<ViewV2, "id" | "version">) {
const seen: Record<string, Record<CalculationType, boolean>> = {}
const calculationFields = helpers.views.calculationFields(view)
for (const name of Object.keys(calculationFields)) {
const schema = calculationFields[name]
const isCount = schema.calculationType === CalculationType.COUNT
const isDistinct = "distinct" in schema
if (isCount && isDistinct) {
// We do these separately.
continue
}
if (seen[schema.field]?.[schema.calculationType]) {
throw new HTTPError(
`Duplicate calculation on field "${schema.field}", calculation type "${schema.calculationType}"`,
400
)
}
seen[schema.field] ??= {} as Record<CalculationType, boolean>
seen[schema.field][schema.calculationType] = true
}
}
function guardDuplicateCountDistinctFields(
view: Omit<ViewV2, "id" | "version">
) {
const seen: Record<string, Record<CalculationType, boolean>> = {}
const calculationFields = helpers.views.calculationFields(view)
for (const name of Object.keys(calculationFields)) {
const schema = calculationFields[name]
const isCount = schema.calculationType === CalculationType.COUNT
if (!isCount) {View on GitHub (pinned to a81a902e9a)
Solutions
- Remove or rename the duplicate calculation entry so each field+calculationType pair is unique
- Give one of the duplicates a different calculationType if both are needed
- Distinct COUNT duplicates should use the distinct form, which is tracked separately
Example fix
// before
calculations: { rev1: { field: "revenue", calculationType: "sum" }, rev2: { field: "revenue", calculationType: "sum" } }
// after
calculations: { rev_sum: { field: "revenue", calculationType: "sum" }, rev_avg: { field: "revenue", calculationType: "avg" } } Defensive patterns
Strategy: validation
Validate before calling
const seen = new Set()
for (const c of Object.values(view.calculations ?? {})) {
if (c.calculationType === "count" && "distinct" in c) continue
const key = `${c.field}:${c.calculationType}`
if (seen.has(key)) throw new Error(`Duplicate calculation: ${key}`)
seen.add(key)
} Try / catch
try { await sdk.views.create(tableId, view) }
catch (e) {
if (e instanceof HTTPError && e.status === 400 && /Duplicate calculation/.test(e.message)) {
// dedupe view.calculations then retry
} else throw e
} Prevention
- Enforce unique field+calculationType pairs when building the view UI
- Deduplicate generated calculation schemas before submitting
- Add client-side validation mirroring the server guard
When it happens
Trigger: Creating/updating a view whose calculation schema defines two named calculation fields pointing at the same schema.field with the same calculationType (excluding COUNT distinct, handled separately).
Common situations: Builder duplicating a calculation column without changing target field; scripted view generation producing repeated aggregates like sum(revenue) twice under different names.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- Duplicate calculation on field "${schema.field}", calculatio
- Calculation field "${name}" is missing a "field" property
- Calculation field "${name}" references field "${schema.field
- Calculation field "${name}" references field "${schema.field
- Cannot insert rows through a calculation view
AI-assisted analysis of Budibase/budibase@a81a902e9a (2026-08-29).
Data as JSON: /api/errors/1811bfad12e36e35.
Report an issue: GitHub.