Using the dataset III
In the sections Introduction to datasets up to and including Using the dataset II we created a model that will be used here. If you haven’t done these, it is highly recommended to do so.
In this section, we will use our own function to calculate an up-to-date version of the age of our employees. This will be done in three steps: adding a new column to our dataset, looping through the dataset and filling out the new column. Lastly, we will present it to the user as done in the previous section.
Adding a new column
Before we are going to calculate a new age, we first need a place to store this information. To do so, we will edit our dataset type created in Creating your first dataset. Go to the node ‘add_dataset’ and open the action createdataset
. Here, click the edit button, presenting you with the dataset type you created earlier. Next, press
to add another variable. Enter ‘correct_age’ and press
OK
. Press OK
and OK
again to close the dataset window.

That’s it! Our dataset now has an extra, empty column ready to be filled!
Looping through our dataset
If you are not familiar with repeating/looping, please take a look at repeating in the Berkeley Studio.
We will now add a new node called ‘looping’ to the node ‘done’. This node will need to import the dataset from the node ‘add_dataset’ as done earlier. You can add the following formula to our ‘looping’ node:

Our graph should look something like this:

Now that we have the dataset, we’re going to loop through each iteration (row) of the dataset. This is done by using [Actions > Repeat]
. Add the repeat
and to make sure we go through each row once, let the repeat end when counter = 7
. Inside the loop, add another formula. This formula will fill our new column ‘correct_age’. You can do this by adding a new formula:

Note the different elements: we use ds_employees.data.correct_age
to access the dataset, the [counter]
to find the right row and the 1
to assign a (temporary) value to the row. The order of your actions is also relevant. The first formula, importing the dataset, needs to be first, then the repeat and within the repeat we need the second formula:

Now that we constructed a loop through our dataset, let’s give it the right value!
Functions in datasets
The functions to calculate the age of an employee are explained and demonstrated in the guided tour. If you want or need more information on functions, please see Formulas and functions. In order to calculate the right age, we need to replace the = 1
by the correct function. To calculate someone’s age, we will use the age()
and now()
functions - the first calculates the age given two dates, the second is the current data. The complete formula therefore becomes ds_employees[counter].data.correct_age = age(now(), ds_employees[counter].data.age)
:

That’s it! If we want to visualize this data we can easily repeat the process done in Using the dataset II (under 'Showing the selection) to create a grid. This will give the following result:
