{"record":{"id":"ecfa1aec6264c9c4","repo":"Budibase/budibase","slug":"calculation-field-name-references-field-sc-ecfa1a","errorCode":null,"errorMessage":"Calculation field \"${name}\" references field \"${schema.field}\" which is not a numeric field","messagePattern":"Calculation field \"(.+?)\" references field \"(.+?)\" which is not a numeric field","errorType":"validation","errorClass":"HTTPError","httpStatus":400,"severity":"error","filePath":"packages/server/src/sdk/workspace/views/index.ts","lineNumber":190,"sourceCode":"        400\n      )\n    }\n\n    const targetSchema = table.schema[schema.field]\n    if (!targetSchema) {\n      throw new HTTPError(\n        `Calculation field \"${name}\" references field \"${schema.field}\" which does not exist in the table schema`,\n        400\n      )\n    }\n\n    const isCount = schema.calculationType === CalculationType.COUNT\n    if (\n      !isCount &&\n      !isNumeric(targetSchema.type) &&\n      !isNumericStaticFormula(targetSchema)\n    ) {\n      throw new HTTPError(\n        `Calculation field \"${name}\" references field \"${schema.field}\" which is not a numeric field`,\n        400\n      )\n    }\n  }\n\n  const groupByFields = helpers.views.basicFields(view)\n  for (const groupByFieldName of Object.keys(groupByFields)) {\n    const targetSchema = table.schema[groupByFieldName]\n    if (!targetSchema) {\n      throw new HTTPError(\n        `Group by field \"${groupByFieldName}\" does not exist in the table schema`,\n        400\n      )\n    }\n\n    if (!canGroupBySchema(targetSchema)) {\n      throw new HTTPError(","sourceCodeStart":172,"sourceCodeEnd":208,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/sdk/workspace/views/index.ts#L172-L208","documentation":"Non-COUNT calculations (sum, avg, min, max, etc.) require a numeric target column. The guard accepts numeric types and numeric static-formula fields but throws 400 if the referenced field is e.g. a string or date. COUNT is exempt because it counts rows regardless of type.","triggerScenarios":"Defining sum/avg/min/max on a string, boolean, date, or non-numeric formula column in a calculation view.","commonSituations":"Selecting the wrong column in the builder; column type changed from number to string after the view was made; formula fields that don't resolve to numeric static formulas.","solutions":["Point the calculation at a numeric column (or numeric static formula field)","Use COUNT if you only need row counts on the non-numeric field","Change the column type to number if the data is genuinely numeric","Cast/coalesce the value into a numeric formula column first"],"exampleFix":"// before\ncalculations: { nameSum: { field: \"customer_name\", calculationType: \"sum\" } }\n// after\ncalculations: { nameCount: { field: \"customer_name\", calculationType: \"count\" } }\n// or: amountSum: { field: \"amount\", calculationType: \"sum\" }","handlingStrategy":"validation","validationCode":"const table = await sdk.tables.getTable(tableId)\nfor (const c of Object.values(view.calculations ?? {})) {\n  if (c.calculationType === \"count\") continue\n  const s = table.schema[c.field]\n  if (!isNumeric(s?.type) && !isNumericStaticFormula(s)) throw new Error(`${c.field} is not numeric`)\n}","typeGuard":"function isNumericTarget(s: TableSchema[string] | undefined): boolean {\n  return !!s && (isNumeric(s.type) || isNumericStaticFormula(s))\n}","tryCatchPattern":"try { await sdk.views.create(tableId, view) }\ncatch (e) {\n  if (e instanceof HTTPError && e.status === 400 && /not a numeric field/.test(e.message)) {\n    // switch calculation to count or pick a numeric field, then retry\n  } else throw e\n}","preventionTips":["Restrict non-count calculation targets to numeric columns in the UI","Re-validate views when column types change","Prefer COUNT when the column is not numeric"],"tags":["http-400","views","validation","calculations","type-mismatch"],"backgroundTag":"schema-validation-failed","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}