{"record":{"id":"b5b079082cdbb34f","repo":"Budibase/budibase","slug":"calculation-views-can-only-have-a-maximum-of-5-fie","errorCode":null,"errorMessage":"Calculation views can only have a maximum of 5 fields","messagePattern":"Calculation views can only have a maximum of 5 fields","errorType":"validation","errorClass":"HTTPError","httpStatus":400,"severity":"error","filePath":"packages/server/src/sdk/workspace/views/index.ts","lineNumber":161,"sourceCode":"        400\n      )\n    }\n    seen[schema.field] ??= {} as Record<CalculationType, boolean>\n    seen[schema.field][schema.calculationType] = true\n  }\n}\n\nasync function guardCalculationViewSchema(\n  table: Table,\n  view: Omit<ViewV2, \"id\" | \"version\">\n) {\n  const calculationFields = helpers.views.calculationFields(view)\n\n  guardDuplicateCalculationFields(view)\n  guardDuplicateCountDistinctFields(view)\n\n  if (Object.keys(calculationFields).length > 5) {\n    throw new HTTPError(\n      \"Calculation views can only have a maximum of 5 fields\",\n      400\n    )\n  }\n\n  for (const name of Object.keys(calculationFields)) {\n    const schema = calculationFields[name]\n    if (!schema.field) {\n      throw new HTTPError(\n        `Calculation field \"${name}\" is missing a \"field\" property`,\n        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`,","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/sdk/workspace/views/index.ts#L143-L179","documentation":"Calculation views are limited to at most 5 calculation fields; the guard counts the entries in the view's calculation schema and rejects anything larger with 400. This keeps aggregate queries against external datasources bounded.","triggerScenarios":"Creating or updating a calculation view whose calculationFields map contains 6 or more keys.","commonSituations":"Aggressive dashboards trying to compute many aggregates in one view; bulk-generated view definitions; merging several views' calculations into one.","solutions":["Split the calculations across multiple views (max 5 each)","Remove the least important calculation fields","Aggregate the rest in the client or a dedicated query"],"exampleFix":"// before\ncalculations: { a: {...}, b: {...}, c: {...}, d: {...}, e: {...}, f: {...} } // 6 fields\n// after\nview1.calculations = { a: {...}, b: {...}, c: {...}, d: {...}, e: {...} }\nview2.calculations = { f: {...} }","handlingStrategy":"validation","validationCode":"if (Object.keys(view.calculations ?? {}).length > 5) throw new Error(\"Max 5 calculation fields per view\")","typeGuard":null,"tryCatchPattern":"try { await sdk.views.create(tableId, view) }\ncatch (e) {\n  if (e instanceof HTTPError && e.status === 400 && /maximum of 5/.test(e.message)) {\n    // split into multiple views\n  } else throw e\n}","preventionTips":["Cap calculation field pickers at 5 in the UI","Split heavy aggregate sets across multiple views","Count entries before submission"],"tags":["http-400","views","validation","limit"],"backgroundTag":"limit-exceeded","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}