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. If a field is greyed out, point at it to see why. If the reason is your licence, 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. 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**.
**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.
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 that has a submenu: open the 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 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. 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  **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 shows each name it cannot find in a tooltip. 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.
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 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
If a circular reference arises any other way, KOSMA does not save the formula. If the formula of a budget line uses a variable that depends on account sums, you see:
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 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:
The expression "{part}" refers to something that does not exist. 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.
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, and in the other formula fields it shows the same text as a short message:
The expression "{part}" contains a decimal comma, which a formula cannot read. Write decimals with a point, for example 2.5\*3, and leave out thousands separators.
Click **Ok** where there is a window, then type the number again with a point.
Markdown