LESSON 8: Inserting and getting a specific value into a table

The aim of this lesson is getting and inserting specifics values from and into a table on Dinamica. We will use the Get Set Table Value, Add Table Column, Set Table by Key and Get Table from Key functors and the following files:

The IBGE crop information Table (Guidebook_Dinamica_5\Database\Tables\IBGE_crop_information.csv)

The 1999_production_value Table (Guidebook_Dinamica_5\Database\Tables\1999_production_value.csv)

The 1999_harvested_area Table (Guidebook_Dinamica_5\Database\Tables\1999_harvested_area.csv.csv)

The 1999_production Table (Guidebook_Dinamica_5\Database\Tables\1999_production.csv)

Let's go!

From the Input/Output tab, grab a Load Table and place it on the sketch. Double click it, browse to the folder Guidebook_Dinamica_5\Database\Tables and open the IBGE_crop_information.csv file.
<note important> Only multi-column CSV - comma separated value format is accepted </note>
* The first two columns are considered the keys of the file, being used to access a certain data in the table. Click on eye button of Load Table to see the table.
* Grab a Get Table Value and place it on the sketch. Connect Load Table to Get Table Value.
* Double click the Get Table Value to enter the keys corresponding to the sought-after values and the column name (highlighted by an asterisk). In the box Keys, enter 2001. Next, enter 1 (The Key to identify the wanted value on the table). Also, in the Column tab, add 4, i.e., the column name or index where the value is located.
<note> If the given keys are not found in the input table and the Value If Not Found parameter, in the Advanced Tab, is not provided, an error will be reported. </note>
* From the Table tab, grab a Calculate Value and place it on the sketch. Assign a number to Number Value and connect the Get Table Value to Number Value. In the Connect ports window, select Value.
* Double-click on Calculate value to add a logic or an algebraic expression. We divide v1 (the selected value) by 1000, v1/1000, and click OK.
* From the Table tab grab a Set Table Cell Value and place it on the sketch. Connect Calculate Value and Load Table to Set Table Cell Value. In the Connect ports window, select Value input port for the output of Calculate Value.
* Double-click Set Table Cell Value. To identify where the sought-after value is located, on the Keys tab enter 2001, 1 (corresponding to Year 2001 and Crop 1) and add the Index 4 on the Column'' tab.

From the Input/Output tab, grab a Save Table and place it on the sketch. Connect Set Table Cell Value to Save Table, select a folder and chose a file name (e.g. IBGE_crop_information_update.csv). The final model will look like this:

Save and run your model. Click on eye button of “Save Table” to see the result.

Congratulations, you have successfully completed this lesson!

☞ Next Lesson
☞ Back to Guidebook Start