Formulas
A Bases formula field computes a record value from the data in its table. UniverBasesPlugin registers the formula engine dependency automatically.
Register formula support
TypeScript
import { UniverBasesPlugin } from '@univerjs-pro/bases'import { UniverBasesUIPlugin } from '@univerjs-pro/bases-ui'univer.registerPlugin(UniverBasesPlugin)univer.registerPlugin(UniverBasesUIPlugin)Create a formula field
TypeScript
const formulaTableName = table.getFormulaName()const total = table.addField('Total', univerAPI.Enum.BaseFieldType.Formula, { field: { config: { formula: `=SUM(${formulaTableName}[[#This Row],[Price]],${formulaTableName}[[#This Row],[Tax]])`, }, }, externalReferences: [],})Every write to a formula field must include externalReferences. Pass [] only when the formula references fields in the same Base. For cross-unit formulas, use buildReference and include every stable source binding in the array.
Notes
- A formula field holds a derived value, so application code should not write to formula cells directly.
- Formula expressions use structured field references, for example
Table[[#This Row],[Price]]. - After importing a large snapshot, recalculate formulas before presenting results to users.
How is this guide?