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 every other field that takes a formula. You pick variables, functions and accounts from a menu, so you do not have to type their names. If a field is greyed out, point at it. KOSMA shows the reason. See [what your licence includes](/kb/article/what-your-licence-includes).
Double-click a **Quantity**, **Price/Unit** or **X** cell, or start typing in it. KOSMA opens the formula editor over the cell, wide enough that the row does not cut off its menu. 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 `↓`.
At the top, the menu shows up to two items you inserted recently in this project, above a line. Below the line are **Variables** and **Functions**. A row with  opens a submenu.
**Variables** opens **Phases**, **Subtotals** and one row for each of your own variable groups that is not hidden. Each of them lists its variables with their current value. **Subtotals** appears only in fields that offer subtotals. In **Quantity**, **Price/Unit** and **X**, the row is missing, so `NPC`, `GT` and `DFFF` are not offered there. **Functions** opens the list of functions.
Use these keys in the menu:
- `↑` `↓`: move up or down; after the last row, the selection starts again at the first. - `→` or `Enter` on a row with : open its submenu. - `←`: close the submenu. - `Enter` on a name: insert the name. - `Esc`: close the menu.
If you type letters instead of picking, the menu shows a list of matching names under **Recent**, **Functions** and **Variables**. You can also type a whole name by hand. If the name is misspelled, KOSMA marks the formula as invalid (see below). A name you pick from the menu is always spelled correctly.
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 decimals with a point in every language, for example `2000.50`. KOSMA shows the result in the number format of your language.
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. The list shows ten rows at a time; scroll to see more.
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 . 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 `_ + - * / ( ) . ,` - 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
In a tooltip, KOSMA shows each name it cannot find. If several names are unknown, the tooltip lists them, separated by commas:
Unknown part of expression: {name}
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. In **Variables** and **Extra Costs**, KOSMA shows one of these messages:
Expression cannot be empty.
Unbalanced parentheses in expression.
Expression contains invalid characters.
Expression references an unknown identifier.
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. When you point at one, KOSMA shows:
Using this would create a circular reference
In all other cases, KOSMA does not save the formula and shows one of these messages. If the formula of a budget line uses a variable that depends on account sums:
This variable depends on account sums, so using it in a budget line would create a circular reference.
If the formula of an account uses the total of that same account:
This formula would make the account's total depend on itself, which creates a circular reference.
For any other circular reference:
This formula creates a circular reference, so the change could not be saved.
A red frame means that the formula names something that no longer exists, such as a deleted account, company, tag or variable. KOSMA also frames a formula it cannot read, such as `2000,50` with a decimal comma. When you point at the cell, KOSMA shows:
Unknown part of expression
The formula editor shows the same text under the field. The cell has no value. If the formula names a deleted variable, the cell keeps the last result of the formula instead.
In Budgeting, right after you save a formula that names something that no longer exists, KOSMA shows **Unknown Reference** once:
The expression "{part}" refers to something that no longer exists. Fix the formula to clear the error.
Click **Ok**. Then change the formula so that it names something that exists, for example by picking another account from the menu. KOSMA removes the red frame. Nothing else in the cell needs fixing.
Markdown