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

  1. Use a supported calculation exactly as defined in SCHEMA_MAP (e.g. COUNT, SUM, MIN, MAX, AVG)
  2. Match the enum casing (uppercase) when constructing the view payload
  3. 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

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


AI-assisted analysis of Budibase/budibase@a81a902e9a (2026-08-29). Data as JSON: /api/errors/457d73c08b728644. Report an issue: GitHub.