Getting started with formulas

This section will introduce you to an important aspect of the Studio: formulas. Formulas allow you to calculate things based on your user’s input. This could be a rather simple calculations, such as adding or subtracting numbers, but you can also more use complex formulas. Furthermore, the Berkeley Studio has several pre-made formulas called functions.

Adding a formula

To add a formula, go to the Action menu and select (formula icon) formula.

adding a formula
adding a formula

A new window will pop up:

formula window
formula window

Here, you can enter a name, condition and the formula itself. For now, we will only discuss the formula. For the name, pick anything that describes the formula. Conditions are explained in a while in Conditions. To show the possibilities of formulas, we will provide a few examples.

Formula example

In a new decision tree model, add two (question icon) questions to the node start: one called number1 and one called number2. Use Number as input type for the questions. These will be the numbers that will be used for the calculations.

Adding a question with number input
Adding a question with number input

In the same node, you can define the formulas. Add a formula by going to Actions in the menu and click Formula. You can name the formula ‘addition’, and leave the condition empty. To add the two numbers, enter the following in the formula field:

main.start.number1 + main.start.number2

Click Ok and the formula should be added to your Actions panel. You might wonder why we used such a specific notation in the formula field. In general, we refer to questions and other variables with their graph name, node name and their own name. So main.start.number1 is a question called number1, in node start in graph main. This way the studio knows exactly which question you mean to use.

It is important to keep this in mind and to place the dots correctly. For more information on the structure of a model, see Model flow.

It is also important to note that you should be careful what name you attach to a variable. You can imagine that, if we would have called our ‘number1’ variable ‘enter_a_number1’, our syntax would become quite long. Always use short names that indicate what the variable is about.

Now, in the same node start, you can add more formulas that subtract, divide or multiply number1 and number2. To do so, use the minus sign (-) for subtraction, an asterix (*) for dividing and a slash (/) for dividing.

After adding these formulas, the ‘Actions’ panel of the ‘start’ node should look similar to the picture below:

actions panel after adding formula
actions panel after adding formula

Showing your formulas

Now that you have the decision tree model do some calculations for you, it would be nice if you could show the results of these calculations.

Add a (add node icon) new node and name it ‘result’. This will be the node in which you will show the answers of the calculations done. In this node, you can add a text by going to Actions and select (text icon) Text. In this text you can show the formula we just made.

The variable that you want to show is in the start node of the main graph and its name is addition. So in order to show it, we need all those: main for the graph, start for the node and addition for the formula itself.


Important: When you place a variable in a text, you should use a caret sign (^) in front of the syntax. Thus, the syntax will be:


In the example, a bit more text is added. Subtraction, division and multiplication have been added as well. It should look similar to:

Formulas in a text
Formulas in a text

If everything went fine, you should be able to save your decision tree model and run it. You need to fill in two numbers and the decision tree model calculates the formulas you defined. The answers should be shown as well.