Budibase/budibase · error · HTTPError
Invalid calculation type: ${calculation}
Error message
Invalid calculation type: ${calculation} What it means
Table views support a fixed set of calculation/aggregation types defined by SCHEMA_MAP (e.g. COUNT, SUM, MIN, MAX, AVG). validateCalculation throws HTTP 400 when a calculation string is supplied that is not a key of SCHEMA_MAP.
Source
Thrown at packages/server/src/api/controllers/view/viewBuilder.ts:98
},
count: {
type: "number",
},
sumsqr: {
type: "number",
},
avg: {
type: "number",
},
},
}
function validateCalculation(calculation?: string) {
if (
calculation &&
!Object.prototype.hasOwnProperty.call(SCHEMA_MAP, calculation)
) {
throw new HTTPError(`Invalid calculation type: ${calculation}`, 400)
}
}
/**
* Iterates through the array of filters to create a JS
* expression that gets used in a CouchDB view.
* @param filters - an array of filter objects
* @returns JS Expression
*/
function parseFilterExpression(filters: ViewFilter[]) {
const expression = []
let first = true
for (let filter of filters) {
if (!first && filter.conjunction) {
expression.push(tokenOrThrow("conjunction", filter.conjunction))
}
View on GitHub (pinned to a81a902e9a)
Solutions
- Use a supported calculation exactly as defined in SCHEMA_MAP (e.g. COUNT, SUM, MIN, MAX, AVG)
- Match the enum casing (uppercase) when constructing the view payload
- Fetch an existing valid view (GET) and copy its calculation value as a reference
Example fix
// before
{ calculation: "average", field: "price" }
// after
{ calculation: "AVG", field: "price" } Defensive patterns
Strategy: validation
Validate before calling
const CALCULATIONS = ["COUNT","SUM","MIN","MAX","AVG"]
function assertCalculation(calc) {
if (calc && !CALCULATIONS.includes(calc)) {
throw new Error(`calculation must be one of ${CALCULATIONS.join(",")}`)
}
} Type guard
const isCalculation = (c) => typeof c === "string" && ["COUNT","SUM","MIN","MAX","AVG"].includes(c)
Try / catch
try {
await api.saveView({ calculation, field, tableId })
} catch (e) {
if (e?.status === 400 && /Invalid calculation type/.test(e.message)) {
// map to the closest supported calculation and retry
} else throw e
} Prevention
- Reference the calculation enum from @budibase/types instead of raw strings
- Normalize user-supplied aggregations to uppercase supported values
- Reject unsupported stats (median, stddev) at the UI layer
- Copy calculation values from existing valid views when scripting
When it happens
Trigger: Creating/saving a table view (v2) with a calculation field set to an unsupported or misspelled value such as "count" lowercase, "average", "median", or null-adjacent typos.
Common situations: API clients building views with wrong enum casing; migrations from older view formats with renamed calculations; UI integrations passing a raw user string as calculation.
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
- Error getting status
- Unable to remove doc without a valid _id and _rev.
- Cannot store document without _id field.
- Configuration invalid. Must contain google clientID and clie
- Configuration invalid. Must contain clientID, clientSecret,
AI-assisted analysis of Budibase/budibase@a81a902e9a (2026-08-29).
Data as JSON: /api/errors/457d73c08b728644.
Report an issue: GitHub.