Budgeting
You can build a formula from variables, functions and accounts you pick in a menu, and you know what each formula error means.
You write a formula in the **Quantity**, **Price/Unit** or **X** cell of an account or subaccount, and in the other formula fields listed in step 1. You pick variables, functions and accounts from a menu instead of typing their names.
Double-click a **Quantity**, **Price/Unit** or **X** cell, or start typing in it. KOSMA opens the formula editor over the cell. The same editor opens in the **Base** column of the markups, in **Calculation Formula** in **Variables**, in **Quantity** and **Price** in **Extra Costs**, in **Factor** of a wage supplement or an extra cost, and in **Timebase (days) for fringe limits** of a fringe.
When the field is empty, or the cursor is right after `+`, `-`, `*`, `/`, `(` or `,`, KOSMA opens the menu. You can also open it with `↓`.
**Variables** opens a submenu for **Phases**, one for **Subtotals** and one for each of your own variable groups. Hidden groups are left out. Each submenu lists its variables with their current value. **Quantity**, **Price/Unit** and **X** have no **Subtotals**, so you cannot pick `NPC`, `GT` or `DFFF` there. **Functions** opens the list of functions.
If you type letters instead of picking, the menu shows matching names under **Recent** (the items you inserted last), **Functions** and **Variables**. If you type a whole name by hand and misspell it, KOSMA shows **Invalid** (see below).
Type `+`, `-`, `*` or `/` between the entries, and group them with `(` and `)`. After each operator, KOSMA opens the menu again, so you can build the whole formula from the menu.
In a formula, write numbers with a decimal point and no thousands separator: 2,500.75 becomes `2500.75`. A comma in a formula only separates the arguments of a function. In a cell that holds only a number, you can type a decimal comma: KOSMA stores `2000,50` as `2000.50`. KOSMA shows the result in the number format of your language. In a language that writes decimals with a comma, KOSMA does not store a number such as `1.000` or `2.500` and shows **Ambiguous Number**, because the point could separate thousands or decimals. Type `1000` for one thousand, or `1` for one.
Under **Functions**, open `ACCOUNT` and pick an account. KOSMA writes the whole call into the field, for example for account 2.01 Lead Actor 1:
`SUM_COMPANY` and `COUNT_COMPANY` list companies in the same way, and `SUM_TAG` and `COUNT_TAG` list tags.
In the Demo Project, the budget Demo Feature has this formula in account 9.03 Financing & Bank Costs, in **Price/Unit**:
Account 9.02 Legal & Accounting is 16,000, so the price per unit is 12,000.
You use the same menu to [reference another account in a formula](/kb/article/reference-another-account-in-a-formula).
Leave the field. The cell shows the result of the formula. To see the formula instead, click  **Switch value/expression display**. See [switch between values and formulas](/kb/article/switch-between-values-and-formulas).
If KOSMA cannot read the formula while you type, it shows the red **Invalid** badge. The menu stays hidden until the formula is valid again. A formula is invalid if it contains:
- a character other than letters, digits, spaces and `_ + - * / ( ) . ,` (any character is allowed inside quotation marks) - a parenthesis without its partner - a quotation mark without its partner - a name that this field does not offer - a function that this field does not offer
When you point at the red **Invalid** badge, KOSMA names each name it cannot find.
Correct the name, or delete it and pick it from the menu.
If you leave the field while the entry is invalid or empty, KOSMA keeps the previous formula. Emptying the field therefore does not remove a formula. In the budget, KOSMA shows no message.
The budget makes one exception for names KOSMA cannot find, such as a misspelled variable or one that does not exist yet. In **Quantity**, **Price/Unit**, **X** and a markup's **Base**, KOSMA saves such a formula exactly as you typed it. The cell then gets a red frame (see below). This applies only when the unknown name is the formula's only problem. A function the field does not offer, such as `GT` in a **Base**, is not accepted, and KOSMA keeps the previous formula.
In **Variables** and **Extra Costs**, KOSMA keeps the previous formula in every case and shows an error: for an empty entry (`KOSMA-E-4006`), a missing parenthesis (`KOSMA-E-4007`), an invalid character (`KOSMA-E-4008`) or an unknown name (`KOSMA-E-4010`).
A formula cannot use its own result. In **Quantity**, **Price/Unit** and **X**, KOSMA greys out every account, company or tag in the list that would make the row depend on itself.
If a circular reference arises any other way, KOSMA does not save the formula and shows an error: `KOSMA-E-3007` when a budget line uses a variable that depends on account sums, `KOSMA-E-3008` when an account's formula uses that account's own total, and `KOSMA-E-3009` for any other circular reference.
A red frame means that the formula names something that does not exist, such as a mistyped name or a deleted account, company, tag or variable. When you point at the cell, KOSMA shows **Unknown part of expression**.
The formula editor shows the same text under the field. The cell then has no value. If the formula names a deleted variable, the cell shows the last result of the formula instead.
In Budgeting, KOSMA also shows the **Unknown Reference** window once, right after you save such a formula.
Change the formula so that it names something that exists, for example by picking another account from the menu. KOSMA removes the red frame.
KOSMA does not save a formula with a decimal comma, such as `2,5*3`. The cell keeps its previous formula, so it gets no red frame. In Budgeting KOSMA shows the **Decimals Need a Point** window, in the other formula fields a short message. Type the number again with a point, for example `2.5*3`.
Markdown